]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elfcmp: Handle bad sections without crashing.
authorMark Wielaard <mark@klomp.org>
Sun, 28 Apr 2019 15:06:50 +0000 (17:06 +0200)
committerMark Wielaard <mark@klomp.org>
Sun, 28 Apr 2019 15:06:50 +0000 (17:06 +0200)
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
src/elfcmp.c

index 57db6cadb6ffb6e1ae6d17044900758ca4c3632f..3786f343227fc34f48781f1652872c0fbc04cafc 100644 (file)
@@ -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
index d5dc1ff2b932e6c48547392d499ef72f140d0fc2..c07fdfd7fe73b64beb3f6e56074f9d6f3fb92d93 100644 (file)
@@ -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)