From 46b37c0b6a69ab22df69eb54bebd4a9e45ff8dac Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 17 Jan 2017 15:39:52 +0100 Subject: [PATCH] tool/dump_pklg: report offset in case of invalid frame/error --- tool/dump_pklg.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tool/dump_pklg.py b/tool/dump_pklg.py index 770a63bc9..b07dcab01 100755 --- a/tool/dump_pklg.py +++ b/tool/dump_pklg.py @@ -41,6 +41,7 @@ if len(sys.argv) == 1: infile = sys.argv[1] with open (infile, 'rb') as fin: + pos = 0 try: while True: len = read_net_32(fin) @@ -48,7 +49,11 @@ with open (infile, 'rb') as fin: ts_usec = read_net_32(fin) type = ord(fin.read(1)) packet_len = len - 9; + if (packet_len > 66000): + print ("Error parsing pklg at offset %u (%x)." % (pos, pos)) + break packet = fin.read(packet_len) + pos = pos + 4 + len time = "[%s.%03u]" % (datetime.datetime.fromtimestamp(ts_sec).strftime("%Y-%m-%d %H:%M:%S"), ts_usec / 1000) if type == 0xfc: print time, "LOG", packet @@ -56,5 +61,5 @@ with open (infile, 'rb') as fin: if type <= 0x03: print time, packet_types[type], as_hex(packet) except TypeError: - exit(0) + print ("Error parsing pklg at offset %u (%x)." % (pos, pos))