public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] strip: Always check gelf_update results.
Date: Fri, 18 Jun 2021 15:06:32 +0200	[thread overview]
Message-ID: <20210618130632.22788-1-mark@klomp.org> (raw)

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog |  5 +++++
 src/strip.c   | 13 +++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 698b3c77..9d4ce31d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2021-06-18  Mark Wielaard  <mark@klomp.org>
+
+	* strip.c (remove_debug_relocations): Check gelf_update results.
+	(update_section_size): Likewise.
+
 2021-06-06  Sergei Trofimovich  <slyfox@gentoo.org>
 
 	* elflint.c (buffer_left): Mark as 'static' to avoid external linkage
diff --git a/src/strip.c b/src/strip.c
index 70fc8c03..961b9db5 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -705,17 +705,21 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr *ehdr,
 relocate_failed:
 	      if (relidx != next)
 		{
+		  int updated;
 		  if (is_rela)
-		    gelf_update_rela (reldata, next, rel_p);
+		    updated = gelf_update_rela (reldata, next, rel_p);
 		  else
-		    gelf_update_rel (reldata, next, rel_p);
+		    updated = gelf_update_rel (reldata, next, rel_p);
+		  if (updated == 0)
+		    INTERNAL_ERROR (fname);
 		}
 	      ++next;
 	    }
 
 	  nrels = next;
 	  shdr->sh_size = reldata->d_size = nrels * shdr->sh_entsize;
-	  gelf_update_shdr (scn, shdr);
+	  if (gelf_update_shdr (scn, shdr) == 0)
+	    INTERNAL_ERROR (fname);
 
 	  if (is_gnu_compressed)
 	    {
@@ -952,7 +956,8 @@ update_section_size (Elf_Scn *scn,
   GElf_Shdr shdr_mem;
   GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
   shdr->sh_size = newdata->d_size;
-  (void) gelf_update_shdr (scn, shdr);
+  if (gelf_update_shdr (scn, shdr) == 0)
+    INTERNAL_ERROR (fname);
   if (debugelf != NULL)
     {
       /* libelf will use d_size to set sh_size.  */
-- 
2.18.4


             reply	other threads:[~2021-06-18 13:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 13:06 Mark Wielaard [this message]
2021-07-02 22:38 ` Mark Wielaard

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=20210618130632.22788-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@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).