aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2016-12-05 13:35:50 +0000
committerNick Clifton <nickc@redhat.com>2016-12-05 13:35:50 +0000
commita55c9876bb111fd301b4762cf501de0040b8f9db (patch)
tree70885a7047dbd05d57638c0a2f7462f3b6ef044a /bfd/elf.c
parent88add6d8e794073758b5398c52bbb76ab40a2923 (diff)
downloadgdb-a55c9876bb111fd301b4762cf501de0040b8f9db.zip
gdb-a55c9876bb111fd301b4762cf501de0040b8f9db.tar.gz
gdb-a55c9876bb111fd301b4762cf501de0040b8f9db.tar.bz2
Fix seg-fault attempting to strip a corrupt binary.
PR binutils/20922 * elf.c (find_link): Check for null headers before attempting to match them.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 98be1db..5cfee9c 100644
--- 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 ? */