packet lib: don't crash with bogus ospf packet

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
FUJITA Tomonori 2014-11-30 22:15:22 +09:00
parent df42ea0dc0
commit b00969a317

View File

@ -612,7 +612,7 @@ class OSPFMessage(packet_base.PacketBase, _TypeDisp):
self.authentication = authentication
@classmethod
def parser(cls, buf):
def _parser(cls, buf):
if len(buf) < cls._HDR_LEN:
raise stream_parser.StreamParser.TooSmallException(
'%d < %d' % (len(buf), cls._HDR_LEN))
@ -637,6 +637,13 @@ class OSPFMessage(packet_base.PacketBase, _TypeDisp):
return subcls(length, router_id, area_id, au_type, authentication,
checksum, version, **kwargs), None, rest
@classmethod
def parser(cls, buf):
try:
return cls._parser(buf)
except:
return None, None, buf
def serialize(self):
tail = self.serialize_tail()
self.length = self._HDR_LEN + len(tail)