summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/lib/packet/dhcp.py9
-rw-r--r--ryu/tests/unit/packet/test_dhcp.py4
2 files changed, 12 insertions, 1 deletions
diff --git a/ryu/lib/packet/dhcp.py b/ryu/lib/packet/dhcp.py
index c8fb16a9..5320079a 100644
--- a/ryu/lib/packet/dhcp.py
+++ b/ryu/lib/packet/dhcp.py
@@ -174,7 +174,7 @@ class dhcp(packet_base.PacketBase):
self.options = options
@classmethod
- def parser(cls, buf):
+ def _parser(cls, buf):
(op, htype, hlen) = struct.unpack_from(cls._HLEN_UNPACK_STR, buf)
buf = buf[cls._HLEN_UNPACK_LEN:]
unpack_str = cls._DHCP_UNPACK_STR % (hlen,
@@ -195,6 +195,13 @@ class dhcp(packet_base.PacketBase):
addrconv.ipv4.bin_to_text(giaddr), sname, boot_file),
None, buf[length:])
+ @classmethod
+ def parser(cls, buf):
+ try:
+ return cls._parser(buf)
+ except:
+ return None, None, buf
+
def serialize(self, payload, prev):
seri_opt = self.options.serialize()
pack_str = '%s%ds' % (self._DHCP_PACK_STR,
diff --git a/ryu/tests/unit/packet/test_dhcp.py b/ryu/tests/unit/packet/test_dhcp.py
index 2581e7e1..44a10c50 100644
--- a/ryu/tests/unit/packet/test_dhcp.py
+++ b/ryu/tests/unit/packet/test_dhcp.py
@@ -128,6 +128,10 @@ class Test_dhcp_offer(unittest.TestCase):
eq_(self.boot_file.ljust(128, '\x00'), res.boot_file)
eq_(str(self.options), str(res.options))
+ def test_parser_corrupted(self):
+ buf = self.buf[:128 - (14 + 20 + 8)]
+ _res = self.dh.parser(buf)
+
def test_serialize(self):
data = bytearray()
prev = None