[PATCH] binutils: validate DW_LNE_define_file filename bounds

Jan Beulich jbeulich@suse.com
Fri Nov 27 09:18:55 GMT 2026


On 22.11.2026 11:35, Alhuda Khan wrote:
> readelf -wL can read past the end of the .debug_line buffer on a malformed
> DWARF line program. In display_debug_lines_decoded(), the DW_LNE_define_file
> opcode reads the file name with an unbounded strlen() on op_code_data. If the
> name has no terminating NUL before the end of the opcode payload - which can
> happen once the section is decompressed into an exact-size heap allocation -
> strlen() runs off the end of the buffer, which ASan reports as a
> heap-buffer-overflow.

This wants to be the description of the patch (rather than leaving it empty).

> The patch is attached. It uses memchr() bounded by op_code_end to find the
> terminator, and if there isn't one it warns and stops processing that opcode
> instead of walking past the end.

Commenting on attached (only) patches is a little cumbersome. The result of
memchr() doesn't need casting. Nor does that of xrealloc(), as you touch it
anyway. sizeof() there also wants to prefer an expression over a type. It's
also unclear why during re-indentation all the READ_ULEB()s were unwrapped,
for them to now significantly exceed the line length limit of 80. Line
length is also an issue with the memchr() invocation.

I'll make these adjustments and get the patch in.

A more general question, seeing your several recent contributions: How much
AI was involved in all of this?

Jan


More information about the Binutils mailing list