Skip to content

Commit

Permalink
do not decode ipv6 fragments after the 1st fragment (#576)
Browse files Browse the repository at this point in the history
* do not decode ipv6 fragments after the 1st fragment
* add a unit test
  • Loading branch information
obormot committed May 31, 2021
1 parent 8a79add commit addc5e2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dpkt/ip6.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def unpack(self, buf):
if next_ext_hdr is not None:
self.p = next_ext_hdr

# do not decode fragments after the first fragment
# https://github.com/kbandla/dpkt/issues/575
if self.nxt == 44 and ext.frag_off > 0: # 44 = IP_PROTO_FRAGMENT
self.data = buf
return

try:
self.data = self._protosw[next_ext_hdr](buf)
setattr(self, self.data.__class__.__name__.lower(), self.data)
Expand Down Expand Up @@ -557,3 +563,25 @@ class Proto:
assert 'PROTO' not in IP6._protosw
IP6.set_proto('PROTO', Proto)
assert IP6.get_proto('PROTO') == Proto


def test_ip6_fragment_no_decode(): # https://github.com/kbandla/dpkt/issues/575
from . import udp

# fragment 0
s = (b'\x60\x00'
b'\x00\x00\x00\x2c\x11\x3f\x20\x01\x06\x38\x05\x01\x8e\xfe\xcc\x4a'
b'\x48\x39\xfa\x79\x04\xdc\x20\x01\x05\x00\x00\x60\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x30\xde\xf2\x00\x35\x00\x2c\x61\x50\x4d\x8b'
b'\x01\x20\x00\x01\x00\x00\x00\x00\x00\x01\x03\x69\x73\x63\x03\x6f'
b'\x72\x67\x00\x00\xff\x00\x01\x00\x00\x29\x10\x00\x00\x00\x80\x00'
b'\x00\x00')
frag0 = IP6(s)
assert type(frag0.data) == udp.UDP

s = (b'\x60\x00\x00\x00\x01\x34\x2c\x35\x20\x01\x05\x00\x00\x60\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x30\x20\x01\x06\x38\x05\x01\x8e\xfe'
b'\xcc\x4a\x48\x39\xfa\x79\x04\xdc'
b'\x61\x72\x31\xb9\xc1\x0f\xcf\x7c\x61\x62\x63\x64\x65\x66\x67\x68') # partial data
frag2 = IP6(s)
assert type(frag2.data) == bytes

0 comments on commit addc5e2

Please sign in to comment.