Bug 29339 - elf-helpers: Don't crash on unexpected ELF file
authorDodji Seketeli <dodji@redhat.com>
Fri, 7 Apr 2023 19:11:44 +0000 (21:11 +0200)
committerDodji Seketeli <dodji@redhat.com>
Fri, 7 Apr 2023 19:17:21 +0000 (21:17 +0200)
When get_soname_of_elf_file is given an unexpected ELF file (e.g, a
DWARF file that is at the wrong place in an RPM, for instance) it hits
an assert and aborts.  Ooops.

This patch removes the offending assert from get_soname_of_elf_file.

Note that to reproduce the initial issue one has to type:

  $ fedabipkgdiff --self-compare -a --from fc36 julia

* src/abg-elf-helpers.cc (get_soname_of_elf_file): If the program
header we are looking at is not what we expect, just skip it; do
not abort.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-elf-helpers.cc

index 8ffeefb371fb12ae3fe9d32ad3642ea5b5e753f7..d47c1c39feeb16a2c0efeab0a95397ea52e25038 100644 (file)
@@ -1521,13 +1521,17 @@ get_soname_of_elf_file(const string& path, string &soname)
           Elf_Scn* scn = gelf_offscn (elf, phdr->p_offset);
           GElf_Shdr shdr_mem;
           GElf_Shdr* shdr = gelf_getshdr (scn, &shdr_mem);
+         if (!(shdr == NULL || (shdr->sh_type == SHT_DYNAMIC
+                                || shdr->sh_type == SHT_PROGBITS)))
+           // This program header doesn't look like one we are
+           // looking for.  Skip to the next.
+           continue;
+
           size_t entsize = (shdr != NULL && shdr->sh_entsize != 0
                             ? shdr->sh_entsize
                             : gelf_fsize (elf, ELF_T_DYN, 1, EV_CURRENT));
           int maxcnt = (shdr != NULL
                         ? shdr->sh_size / entsize : INT_MAX);
-          ABG_ASSERT (shdr == NULL || (shdr->sh_type == SHT_DYNAMIC
-                                      || shdr->sh_type == SHT_PROGBITS));
           Elf_Data* data = elf_getdata (scn, NULL);
           if (data == NULL)
             break;