public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Dodji Seketeli <dodji@redhat.com>
To: libabigail@sourceware.org
Subject: [PATCH, applied] elf-helpers: Don't crash on unexpected ELF file
Date: Tue, 11 Apr 2023 12:55:43 +0200	[thread overview]
Message-ID: <87leiyk7rk.fsf@redhat.com> (raw)

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


                 reply	other threads:[~2023-04-11 10:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87leiyk7rk.fsf@redhat.com \
    --to=dodji@redhat.com \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).