Hi, The attached patch makes get_table_for_offset in libdw/dwarf_getmacros.c check the opcode_operands_table form count against the remaining bytes before adding it to readp. A massive ULEB128 nforms currently overflows the pointer addition (undefined behaviour) and can wrap readp back before endp so the existing check passes. The patch adds a regression test based on testfile-macros-opcode0.
clang -fsanitize=pointer-overflow reports the old code on the new test file. GCC appears to be folding the old check into the safe form so the GCC --enable-sanitize-undefined build passes either way. With the patch, make check gives 261 PASS, 8 SKIP and 1 FAIL (run-large-elf-file.sh, killed by the OOM killer on a 7GB machine). Sincerely, Akhil M
0001-libdw-Check-opcode-table-nforms-before-advancing-rea.patch
Description: Binary data
