public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [COMMITTED] elfcmp: Handle bad sections without crashing.
@ 2019-04-28 15:22 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2019-04-28 15:22 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

If we cannot get the Shdr of a section then don't try to use or
compare them.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 4 ++++
 src/elfcmp.c  | 6 +++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 57db6cadb..3786f3432 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2019-04-28  Mark Wielaard  <mark@klomp.org>
+
+	* elfcmp.c (main): Check shdr1 and shdr2 are not NULL.
+
 2019-04-03  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (attr_callback): Print DW_AT_data_member_location as
diff --git a/src/elfcmp.c b/src/elfcmp.c
index d5dc1ff2b..c07fdfd7f 100644
--- a/src/elfcmp.c
+++ b/src/elfcmp.c
@@ -269,7 +269,7 @@ main (int argc, char *argv[])
 	  if (shdr1 != NULL)
 	    sname1 = elf_strptr (elf1, shstrndx1, shdr1->sh_name);
 	}
-      while (scn1 != NULL
+      while (scn1 != NULL && shdr1 != NULL
 	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
 
       GElf_Shdr shdr2_mem;
@@ -282,10 +282,10 @@ main (int argc, char *argv[])
 	  if (shdr2 != NULL)
 	    sname2 = elf_strptr (elf2, shstrndx2, shdr2->sh_name);
 	}
-      while (scn2 != NULL
+      while (scn2 != NULL && shdr2 != NULL
 	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));
 
-      if (scn1 == NULL || scn2 == NULL)
+      if (scn1 == NULL || scn2 == NULL || shdr1 == NULL || shdr2 == NULL)
 	break;
 
       if (gaps != gaps_ignore && (shdr1->sh_flags & SHF_ALLOC) != 0)
-- 
2.20.1

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

only message in thread, other threads:[~2019-04-28 15:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-28 15:22 [COMMITTED] elfcmp: Handle bad sections without crashing Mark Wielaard

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).