Fix seg-fault attempting to strip a corrupt binary.
authorNick Clifton <nickc@redhat.com>
Mon, 5 Dec 2016 13:35:50 +0000 (13:35 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 5 Dec 2016 13:35:50 +0000 (13:35 +0000)
PR binutils/20922
* elf.c (find_link): Check for null headers before attempting to
match them.

bfd/ChangeLog
bfd/elf.c

index 3d9cd9e95a29673d7bb70a5fe36222690da16d13..b84dfab6f540a3f84883522fcb2f217f7be2bf9b 100644 (file)
@@ -1,5 +1,9 @@
 2016-12-05  Nick Clifton  <nickc@redhat.com>
 
+       PR binutils/20922
+       * elf.c (find_link): Check for null headers before attempting to
+       match them.
+
        PR ld/20925
        * aoutx.h (aout_link_add_symbols): Replace BFD_ASSERT with return
        FALSE.
index 98be1db6d789728539e047fff4455f3195cc5dda..5cfee9c58f77c3b70648e2979419367844b630b4 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1271,13 +1271,19 @@ find_link (const bfd * obfd, const Elf_Internal_Shdr * iheader, const unsigned i
   Elf_Internal_Shdr ** oheaders = elf_elfsections (obfd);
   unsigned int i;
 
-  if (section_match (oheaders[hint], iheader))
+  BFD_ASSERT (iheader != NULL);
+
+  /* See PR 20922 for a reproducer of the NULL test.  */
+  if (oheaders[hint] != NULL
+      && section_match (oheaders[hint], iheader))
     return hint;
 
   for (i = 1; i < elf_numsections (obfd); i++)
     {
       Elf_Internal_Shdr * oheader = oheaders[i];
 
+      if (oheader == NULL)
+       continue;
       if (section_match (oheader, iheader))
        /* FIXME: Do we care if there is a potential for
           multiple matches ?  */
This page took 0.030828 seconds and 4 git commands to generate.