From 3cd3df5f94b7022de49a758a7873a22ac89a72f8 Mon Sep 17 00:00:00 2001 From: gpotter2 <10530980+gpotter2@users.noreply.github.com> Date: Sun, 4 Feb 2024 18:01:54 +0100 Subject: [PATCH] Fix in4_pseudoheader being destructive --- scapy/layers/inet.py | 1 + test/scapy/layers/inet.uts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/scapy/layers/inet.py b/scapy/layers/inet.py index f46ed7f5e4e..ec85873df45 100644 --- a/scapy/layers/inet.py +++ b/scapy/layers/inet.py @@ -635,6 +635,7 @@ def in4_pseudoheader(proto, u, plen): :param u: IP layer instance :param plen: the length of the upper layer and payload """ + u = u.copy() if u.len is not None: if u.ihl is None: olen = sum(len(x) for x in u.options) diff --git a/test/scapy/layers/inet.uts b/test/scapy/layers/inet.uts index 5b98c1c74f3..db632831406 100644 --- a/test/scapy/layers/inet.uts +++ b/test/scapy/layers/inet.uts @@ -763,3 +763,12 @@ assert no_sr[UDP].chksum == sr[UDP].chksum sr = IP(raw(IP(options=[IPOption_LSRR(routers=["1.1.1.1"]), IPOption_SSRR(routers=["8.8.8.8"])])/UDP()/DNS())) assert no_sr[UDP].chksum != sr[UDP].chksum + +# GH4174 +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")/ \ + 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"])])/ \ + UDP(sport=1111, dport=2222) / VXLAN() / \ + 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") / \ + TCP() +bytes(sr[UDP]) +assert sr[IP:2].dst == "100.0.0.1"