scapy
scapy copied to clipboard
IPv6 dissection raises IndexError when nh=43 and payload is shorter than 3 bytes
Brief description
IPv6.default_payload_class reads p[2] for nh == 43 without checking len(p), unlike the ICMPv6 and Mobile IPv6 branches above it. A Routing header payload shorter than 3 bytes raises IndexError during dissection.
test/scapy/layers/inet6.uts
Scapy version
2.7.1
Python version
3.12.3
Operating system
Linux
Additional environment information
No response
How to reproduce
from scapy.all import IPv6 IPv6(bytes(IPv6(nh=43, plen=1)) + b"\x00")
Actual result
File "scapy/layers/inet6.py", line 317, in default_payload_class elif self.nh == 43 and p[2] == 4: # Segment Routing header IndexError: index out of range
Expected result
The packet is dissected with a Raw payload, as for other malformed payloads.
Suggested fix:
elif self.nh == 43 and len(p) > 2 and p[2] == 4: # Segment Routing header
Related resources
No response
Thanks for the report