Skip to content

Commit

Permalink
fix parsing of options without policy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstrohman authored and svinota committed Feb 28, 2019
1 parent f1f9e82 commit 79cc149
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pyroute2/dhcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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


Expand Down

0 comments on commit 79cc149

Please sign in to comment.