Skip to content

Commit 9a1ce84

Browse files
authored
Pcapng option bounds check (#4699)
* Fix PCAPNG options bounds check Bounds check in PcapNG options is off-by-one, meaning that tightly packed options accidentally truncate the last option. Use right comparison to get that last option. * Add regression test for PCAPNG options bounds
1 parent 9e4dc1d commit 9a1ce84

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

scapy/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ def _read_options(self, options):
18001800
warning("PcapNg: options header is too small "
18011801
"%d !" % len(options))
18021802
raise EOFError
1803-
if code != 0 and 4 + length < len(options):
1803+
if code != 0 and 4 + length <= len(options):
18041804
opts[code] = options[4:4 + length]
18051805
if code == 0:
18061806
if length != 0:

test/regression.uts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,11 @@ file = BytesIO(b'\xd4\xc3\xb2\xa1\x02\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x0
23482348
l = rdpcap(file)
23492349
assert len(l) == 0 or ARP in l[0]
23502350

2351+
# Read PCAPNG file with tightly packed comment option, no End of Options
2352+
file = BytesIO(b'\n\r\r\n\x1c\x00\x00\x00M<+\x1a\x01\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\x1c\x00\x00\x00\x01\x00\x00\x00\x14\x00\x00\x00\x01\x00\x00\x00\x00\x00\x04\x00\x14\x00\x00\x00\x06\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x08\x00Helloooo,\x00\x00\x00')
2353+
l = rdpcap(file)
2354+
assert len(l) == 1 and l[0].comment == b'Helloooo'
2355+
23512356
= Read a pcap file with wirelen != captured len
23522357
pktpcapwirelen = rdpcap(pcapwirelenfile)
23532358

0 commit comments

Comments
 (0)