packet lib: don't crash with corrupted lldp packet

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Tested-by: Benjamin Eggerstedt <benjamin.eggerstedt@gmail.com>
This commit is contained in:
FUJITA Tomonori 2014-10-26 16:35:37 +09:00
parent f0ab847f64
commit 1f2b24e834
2 changed files with 12 additions and 1 deletions

View File

@ -124,7 +124,7 @@ class lldp(packet_base.PacketBase):
self.tlvs[-1].tlv_type == LLDP_TLV_END)
@classmethod
def parser(cls, buf):
def _parser(cls, buf):
tlvs = []
while buf:
@ -144,6 +144,13 @@ class lldp(packet_base.PacketBase):
return lldp_pkt, None, buf
@classmethod
def parser(cls, buf):
try:
return cls._parser(buf)
except:
return None, None, buf
def serialize(self, payload, prev):
data = bytearray()
for tlv in self.tlvs:

View File

@ -286,6 +286,10 @@ class TestLLDPOptionalTLV(unittest.TestCase):
# End
eq_(tlvs[16].tlv_type, lldp.LLDP_TLV_END)
def test_parse_corrupted(self):
buf = self.data
pkt = packet.Packet(buf[:128])
def test_serialize(self):
pkt = packet.Packet()