Skip to content

Commit 970aa8a

Browse files
authored
Fix in4_pseudoheader being destructive (#4259)
1 parent d3442b4 commit 970aa8a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

scapy/layers/inet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ def in4_pseudoheader(proto, u, plen):
635635
:param u: IP layer instance
636636
:param plen: the length of the upper layer and payload
637637
"""
638+
u = u.copy()
638639
if u.len is not None:
639640
if u.ihl is None:
640641
olen = sum(len(x) for x in u.options)

test/scapy/layers/inet.uts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,12 @@ assert no_sr[UDP].chksum == sr[UDP].chksum
817817

818818
sr = IP(raw(IP(options=[IPOption_LSRR(routers=["1.1.1.1"]), IPOption_SSRR(routers=["8.8.8.8"])])/UDP()/DNS()))
819819
assert no_sr[UDP].chksum != sr[UDP].chksum
820+
821+
# GH4174
822+
sr = Ether(src="de:ad:be:ef:aa:55", dst="ca:fe:00:00:00:00")/IP(src="20.0.0.1",dst="100.0.0.1")/ \
823+
IP(src="20.0.0.1",dst="100.0.0.1", options=[IPOption_SSRR(copy_flag=1, pointer=4, routers=["1.1.1.1", "8.8.8.8"])])/ \
824+
UDP(sport=1111, dport=2222) / VXLAN() / \
825+
Ether(src="de:ad:be:ef:aa:55", dst="ca:fe:00:00:00:00")/IP(src="20.0.0.1",dst="100.0.0.1") / \
826+
TCP()
827+
bytes(sr[UDP])
828+
assert sr[IP:2].dst == "100.0.0.1"

0 commit comments

Comments
 (0)