summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-10-26 16:35:37 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-10-26 16:47:32 +0900
commit1f2b24e8343669a6775cfd57a6755c43a09bb420 (patch)
tree84b1a3d74fe21772eeb84d12e760f2862e34caed
parentf0ab847f64a2d2f9d96d66c2b546ff26e55323a6 (diff)
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>
-rw-r--r--ryu/lib/packet/lldp.py9
-rw-r--r--ryu/tests/unit/packet/test_lldp.py4
2 files changed, 12 insertions, 1 deletions
diff --git a/ryu/lib/packet/lldp.py b/ryu/lib/packet/lldp.py
index 12022250..d0cae2fa 100644
--- a/ryu/lib/packet/lldp.py
+++ b/ryu/lib/packet/lldp.py
@@ -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:
diff --git a/ryu/tests/unit/packet/test_lldp.py b/ryu/tests/unit/packet/test_lldp.py
index 646af1e6..c8daf58c 100644
--- a/ryu/tests/unit/packet/test_lldp.py
+++ b/ryu/tests/unit/packet/test_lldp.py
@@ -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()