packet lib: avoid exception for bogus protocol header parsing

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
FUJITA Tomonori 2013-06-17 20:58:55 +09:00
parent 6080f2c008
commit df42ae87e8

View File

@ -14,6 +14,7 @@
# limitations under the License.
import inspect
import struct
from . import packet_base
from . import ethernet
@ -47,11 +48,13 @@ class Packet(object):
def _parser(self, cls):
while cls:
proto, cls = cls.parser(self.data[self.parsed_bytes:])
if proto:
self.parsed_bytes += proto.length
self.protocols.append(proto)
try:
proto, cls = cls.parser(self.data[self.parsed_bytes:])
if proto:
self.parsed_bytes += proto.length
self.protocols.append(proto)
except struct.error:
cls = None
if len(self.data) > self.parsed_bytes:
self.protocols.append(self.data[self.parsed_bytes:])