aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-10-13 00:21:16 +0200
committerAnders Broman <a.broman58@gmail.com>2018-10-13 05:16:22 +0000
commit22cf80d30d7310554f7b144a31cbdd14451a6d27 (patch)
tree511951b4b047cad7c5ffcd11c0a25b7297b22fba
parent9b72da0cdd7d2cd39f0a50defa5a08ada955e60b (diff)
text2pcap: gracefully handle hexdump without trailing LF
When copying hexdumps, the newline might be missing which would result in a capture file missing one byte in its packet. Adjust the grammar to recognize the two trailing hexadecimal characters as a "byte". This is safe because Flex picks the rule that matches the longest input string. So given "01 ", it will always match all three characters. If something like "01x" is given, then the "text" rule will be matched (as before). Only if no more characters are available (such as at the end of a file), then the rule will match two hexdigits. Remove the unnecessary hexdigit rule while at it. Change-Id: I21dc37d684d1c410ce720cb27706a6e54f87f94d Reviewed-on: https://code.wireshark.org/review/30190 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--test/suite_text2pcap.py7
-rw-r--r--text2pcap-scanner.l3
2 files changed, 8 insertions, 2 deletions
diff --git a/test/suite_text2pcap.py b/test/suite_text2pcap.py
index 09e1b638b4..569f5b5eef 100644
--- a/test/suite_text2pcap.py
+++ b/test/suite_text2pcap.py
@@ -332,6 +332,13 @@ class case_text2pcap_parsing(subprocesstest.SubprocessTestCase):
"7f 00 00 01 ff 98 00 13 00 0d b5 48 66 69 72 73\n"
self.check_rawip(pdata, 0, 0)
+ def test_text2pcap_eol_missing(self):
+ '''Verify that the last LF can be missing.'''
+ pdata = "0000 45 00 00 21 00 01 00 00 40 11 7c c9 7f 00 00 01\n" \
+ "0010 7f 00 00 01 ff 98 00 13 00 0d b5 48 66 69 72 73\n" \
+ "0020 74"
+ self.check_rawip(pdata, 1, 33)
+
def run_text2pcap_content(test, content, args):
testin_file = test.filename_from_id(testin_txt)
diff --git a/text2pcap-scanner.l b/text2pcap-scanner.l
index f1ef1241fb..3a69a83ba1 100644
--- a/text2pcap-scanner.l
+++ b/text2pcap-scanner.l
@@ -68,10 +68,9 @@ DIAG_OFF_FLEX
%}
-hexdigit [0-9A-Fa-f]
directive ^#TEXT2PCAP.*\r?\n
comment ^[\t ]*#.*\r?\n
-byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
+byte [0-9A-Fa-f][0-9A-Fa-f][ \t]?
byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
offset [0-9A-Fa-f]+[: \t]
offset_eol [0-9A-Fa-f]+\r?\n