public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, applied] elf-helpers: Don't crash on unexpected ELF file
@ 2023-04-11 10:55 Dodji Seketeli
  0 siblings, 0 replies; only message in thread
From: Dodji Seketeli @ 2023-04-11 10:55 UTC (permalink / raw)
  To: libabigail

Hello,

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.

	* 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 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

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;
-- 
2.39.2


-- 
		Dodji


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-11 10:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-11 10:55 [PATCH, applied] elf-helpers: Don't crash on unexpected ELF file Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).