Skip to content

Commit

Permalink
Fix bugs with _raw_packet_cache_field_value in cache of payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Jul 1, 2024
1 parent 37d9412 commit a1afb9a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scapy/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,10 @@ def _raw_packet_cache_field_value(self, fld, val, copy=False):
# avoid copying whole packets (perf: #GH3894)
if fld.islist:
return [
_cpy(x.fields) for x in val
(_cpy(x.fields), x.payload.raw_packet_cache) for x in val
]
else:
return _cpy(val.fields)
return (_cpy(val.fields), val.payload.raw_packet_cache)
elif fld.islist or fld.ismutable:
return _cpy(val)
return None
Expand Down
47 changes: 47 additions & 0 deletions test/fields.uts
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,53 @@ while p.pl:

assert i == 100

= Test cache handling of payload modification in a PacketListField
~ field

# GH4414
class SubPacket(Packet):
fields_desc = [
ByteField("b", 0),
]

class MyPacket(Packet):
fields_desc = [
PacketListField("a", [], SubPacket),
]


p = MyPacket(b"\x00extrapayload")
p.a[0] = SubPacket(b=0) / b"test"

assert bytes(p) == b"\x00test"

= Test cache handling of payload modification in a PacketField
~ field

# also GH4414
class PayloadPacket(Packet):
fields_desc = [
StrField("b", ""),
]

class SubPacket(Packet):
fields_desc = []

bind_layers(SubPacket, PayloadPacket)

class MyPacket(Packet):
fields_desc = [
PacketField("a", None, SubPacket),
]


s = b'test'
p = MyPacket(s)

p[PayloadPacket].b = b'new'
assert p.build() != s


############
############
+ Tests on MultiFlagsField
Expand Down

0 comments on commit a1afb9a

Please sign in to comment.