Skip to content

layers.inet.fragment: use fragsize=8 if argument is lower than that #3970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scapy/layers/inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ def mysummary(self):

def fragment(self, fragsize=1480):
"""Fragment IP datagrams"""
fragsize = max(fragsize, 8)
lastfragsz = fragsize
fragsize -= fragsize % 8
lst = []
Expand Down Expand Up @@ -1139,6 +1140,7 @@ def inet_register_l3(l2, l3):
@conf.commands.register
def fragment(pkt, fragsize=1480):
"""Fragment a big IP datagram"""
fragsize = max(fragsize, 8)
lastfragsz = fragsize
fragsize -= fragsize % 8
lst = []
Expand Down
19 changes: 19 additions & 0 deletions test/scapy/layers/inet.uts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ assert len(frags2) == 2
assert len(frags2[0]) == 20 + paylen - paylen % 8
assert len(frags2[1]) == 20 + 1 + paylen % 8

= fragment() with fragsize lower than 8
paylen = 5
fragsize = paylen
frags1 = fragment(IP() / ("X" * paylen), paylen)
assert len(frags1) == 1
assert bytes(frags1[0].payload) == b"X" * paylen

fragsize = paylen + 1
frags2 = fragment(IP() / ("X" * paylen), fragsize)
assert len(frags2) == 1
assert bytes(frags2[0].payload) == b"X" * paylen

paylen = 16
fragsize = 5
frags3 = fragment(IP() / ("X" * paylen), fragsize)
assert len(frags3) == 2
assert bytes(frags3[0].payload) == b"X" * 8
assert bytes(frags3[1].payload) == b"X" * 8

= defrag()
nonfrag, unfrag, badfrag = defrag(frags)
assert not nonfrag
Expand Down