]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdw_open_elf: Avoid invalid free
authorAaron Merey <amerey@redhat.com>
Fri, 5 Sep 2025 19:27:52 +0000 (15:27 -0400)
committerAaron Merey <amerey@redhat.com>
Fri, 5 Sep 2025 19:27:52 +0000 (15:27 -0400)
commitdf9bd6bdc332243d1e3072844e227cac9ec5d025
tree1a3702d42a7dca9312508f66f8ff93cfb699b053
parent54b6f27e2b4dfc7eca4837bf3378bfd7a70822f0
libdw_open_elf: Avoid invalid free

If libdw_open_elf detects an invalid ELF file, it may attempt to
temporarily treat it as an ELF archive in order to check if there's
a valid ELF file following a header.

When doing this, the elf descriptor for the invalid file is given
the dummy state.ar.elf_ar_hdr.ar_name "libdwfl is faking you out".

Afterwards libdw_open_elf will call elf_end on the elf descriptor
for the invalid ELF file.  elf_end will attempt to free the address
of the "libdwfl is faking you out" literal, causing an invalid free.

Fix this by setting the ar_name to NULL before libdw_open_elf calls
elf_end on the descriptor of the invalid ELF file.

Signed-off-by: Aaron Merey <amerey@redhat.com>
libdwfl/open.c