From: Dodji Seketeli Date: Fri, 7 Apr 2023 19:11:44 +0000 (+0200) Subject: Bug 29339 - elf-helpers: Don't crash on unexpected ELF file X-Git-Tag: upstream/2.3~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b0069064ed33b3c95b05f45209286a36a2506e1;p=platform%2Fupstream%2Flibabigail.git Bug 29339 - elf-helpers: Don't crash on unexpected ELF file 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 --- diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc index 8ffeefb3..d47c1c39 100644 --- a/src/abg-elf-helpers.cc +++ b/src/abg-elf-helpers.cc @@ -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;