Skip to content

Commit

Permalink
Don't require newline at end of pcapng comment (#4021)
Browse files Browse the repository at this point in the history
I couldn't find anything in the spec about requiring this.
  • Loading branch information
nkorth authored Jul 18, 2023
1 parent 5bc8fc9 commit eb3658d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
9 changes: 1 addition & 8 deletions scapy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,12 +1553,7 @@ def _read_options(self, options):
tsresol & 127
)
if code == 1 and length >= 1 and 4 + length < len(options):
comment = options[4:4 + length]
newline_index = comment.find(b"\n")
if newline_index == -1:
warning("PcapNg: invalid comment option")
break
opts["comment"] = comment[:newline_index]
opts["comment"] = options[4:4 + length]
if code == 0:
if length != 0:
warning("PcapNg: invalid option length %d for end-of-option" % length) # noqa: E501
Expand Down Expand Up @@ -2210,8 +2205,6 @@ def _write_block_epb(self,
comment_opt = None
if comment:
comment = bytes_encode(comment)
if not comment.endswith(b"\n"):
comment += b"\n"
comment_opt = struct.pack(self.endian + "HH", 1, len(comment))

# Pad Option Value to 32 bits
Expand Down
2 changes: 1 addition & 1 deletion test/regression.uts
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ p = Ether() / IPv6() / TCP()
p.comment = b"Hello Scapy!"
wrpcapng(tmpfile, p)
l = rdpcap(tmpfile)
assert l[0].comment.strip() == p.comment
assert l[0].comment == p.comment

= Read a pcap file with wirelen != captured len
pktpcapwirelen = rdpcap(pcapwirelenfile)
Expand Down

0 comments on commit eb3658d

Please sign in to comment.