From 79cc149ff9e03f249dc92843b139b4b97bf896a4 Mon Sep 17 00:00:00 2001 From: Andy Strohman Date: Wed, 27 Feb 2019 14:21:04 -0800 Subject: [PATCH] fix parsing of options without policy --- pyroute2/dhcp/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pyroute2/dhcp/__init__.py b/pyroute2/dhcp/__init__.py index b1a219821..d599e05be 100644 --- a/pyroute2/dhcp/__init__.py +++ b/pyroute2/dhcp/__init__.py @@ -174,9 +174,9 @@ def encode(self): return self def decode(self): + self.data_length = struct.unpack('B', self.buf[self.offset + 1: + self.offset + 2])[0] if self.policy is not None: - self.data_length = struct.unpack('B', self.buf[self.offset + 1: - self.offset + 2])[0] if self.policy['format'] == 'string': fmt = '%is' % self.data_length else: @@ -192,7 +192,15 @@ def decode(self): value = value[:value.find('\x00')] self.value = value else: + # remember current offset as msg.decode() will advance it + offset = self.offset + # move past the code and option length bytes so that msg.decode() + # starts parsing at the right location + self.offset += 2 msg.decode(self) + # restore offset so that dhcpmsg.decode() advances it correctly + self.offset = offset + return self