]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdwfl: handle duplicate ELFs when reporting archives
authorAleksei Vetrov <vvvvvv@google.com>
Mon, 20 Nov 2023 17:44:47 +0000 (17:44 +0000)
committerMark Wielaard <mark@klomp.org>
Tue, 21 Nov 2023 13:01:29 +0000 (14:01 +0100)
commit0ab5a3eb4122f36cbaff259e7a0a3f9d014cb6f7
treecbb69704bfc28eb5c9395ffa33a7ed2f3e364c32
parent374bf6ab3b79637d02183e10899d40243349e4d1
libdwfl: handle duplicate ELFs when reporting archives

When archive is processed in process_archive (libdwfl/offline.c), it
creates an Elf object for each archive member. Then in
process_archive_member it calls process_file to create a Dwfl_Module
through __libdwfl_report_elf.

The ownership of the Elf object is expected to be:

* either transfered to the Dwfl_Module, if __libdwfl_report_elf returns
  not NULL;

* or handled at the end of process_archive_member by calling elf_end.

Moreover, Elf object is expected to be alive, if __libdwfl_report_elf
returns not NULL, because at the end of process_archive_member it
advances to the next member through the elf_next call.

The problem happens when __libdwfl_report_elf encounters Elf with the
same name and content as it seen before. In that case dwfl_report_module
will reuse existing Dwfl_Module object. This leads to a codepath that
calls elf_end on the Elf object, while returning not NULL, breaking the
elf_next call to the next member.

The fix is to destroy m->main.elf instead and put the new Elf object in
the already existing Dwfl_Module.

    * libdwfl/dwfl_report_elf.c (__libdwfl_report_elf): Replace Elf in
      the Dwfl_Module in case of duplicate modules to prolong its
      lifetime for subsequent processing.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
libdwfl/dwfl_report_elf.c