Fix spurious match of data in DUMP_CHUNK_RE

If the data from `MBEDTLS_SSL_DEBUG_BUF` that's listed in text form after
the hex digits starts with two bytes that happen to be hex digits, this
could be interpreted as an extra pair of hex digits. Fix this.

Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
Gilles Peskine
2026-04-01 09:45:50 +02:00
parent f911af9fc1
commit dd683324d8
+5 -3
View File
@@ -17,13 +17,13 @@ class Info:
r'dumping \'(?P<what>.*?)\' \((?P<length>[0-9]+) bytes\)')
DUMP_CHUNK_RE = re.compile(
PREFIX_RE_S +
r'[0-9a-f]+: +(?P<data>(?:[0-9a-f]{2} *){1,16})')
r'[0-9a-f]+: *(?P<data>(?: [0-9a-f]{2}){1,16})')
VALUE_OF_RE = re.compile(
PREFIX_RE_S +
r'value of \'(?P<what>.*?)\' \((?P<length>[0-9]+) bits\)')
VALUE_CHUNK_RE = re.compile(
PREFIX_RE_S +
r'(?P<data>(?:[0-9a-f]{2} *){1,16})')
r'(?P<data>(?:[0-9a-f]{2}(?:$| )){1,16})')
def __init__(self) -> None:
"""Create an empty log info object."""
@@ -51,7 +51,9 @@ class Info:
acc += m.group('data')
remaining -= 16
plain = acc.replace(' ', '')
assert len(plain) == length * 2
if len(plain) != length * 2:
raise Exception(f'{filename}:{lineno}: '
f'found {len(plain)} hex digits but expected {length * 2}')
return plain
def read_file_contents(self,