-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
There is a bug with MultipleTypeField: when a packet containing it is initialized with a value set to MultipleTypeField, the any2i function is executed to set the value to the field before other fields of the same packet are initialized.
In the case where any2i changes the type of the input, it creates a bug. See demo below.
class DebugPacket(Packet):
fields_desc = [
ByteEnumField("atyp", 0x1, {0x1: "IPv4", 0x3: "DNS", 0x4: "IPv6"}),
MultipleTypeField(
[
# IPv4
(IPField("addr", "0.0.0.0"), lambda pkt: pkt.atyp == 0x1),
# DNS
(DNSStrField("addr", ""), lambda pkt: pkt.atyp == 0x3),
# IPv6
(IP6Field("addr", "::"), lambda pkt: pkt.atyp == 0x4),
],
StrField("addr", "")
),
]- First test (OK)
a = DebugPacket(atyp=0x3, addr="scapy.net")
a = DebugPacket(raw(a))
a.addrReturns:
b'scapy.net.'
- Second test (Fails)
a = DebugPacket(addr="scapy.net", atyp=0x3)
a.addrReturns:
Net('scapy.net')
Ways of fixing this
- Adding some complicated extra metric (see the PR)
- Throwing an error on building when we detect a wrong order of the init fields
Reactions are currently unavailable