mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-01-23 01:21:31 +01:00
packet lib: don't crash with truncated dhcp packet
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
1f2b24e834
commit
df2cf837ab
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user