On Thu, 23 Oct 2014 14:23:27 -0400
Jeff Rasley <[email protected]> wrote:

> More specifically I am getting an "error: 'unpack_from requires a buffer of
> at least 233 bytes'" error from the unpack call on 185 (my buffer appears
> to be 91 bytes long). Which makes me think that the unpack string is not
> representative of my DHCP Discover packet.

As Benjamin suggested, I also suspect that your in_packet_in function
doesn't get the full packet.

https://gist.github.com/jeffra/aa6cf159db53f27922a2#file-gistfile1-py-L3

Adding 'print len(msg.data)' above third line would help.

btw, I think that our library should not crash with any packet so I'll
apply the following patch. With the patch, our library fails to parse
truncated DHCP packet but doesn't crash.

diff --git a/ryu/lib/packet/dhcp.py b/ryu/lib/packet/dhcp.py
index c8fb16a..5320079 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 2581e7e..44a10c5 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

------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to