This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Fix seg-fault attempting to strip a corrupt binary.
- From: Nick Clifton <nickc at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 5 Dec 2016 13:36:26 -0000
- Subject: [binutils-gdb] Fix seg-fault attempting to strip a corrupt binary.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a55c9876bb111fd301b4762cf501de0040b8f9db
commit a55c9876bb111fd301b4762cf501de0040b8f9db
Author: Nick Clifton <nickc@redhat.com>
Date: Mon Dec 5 13:35:50 2016 +0000
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.
Diff:
---
bfd/ChangeLog | 4 ++++
bfd/elf.c | 8 +++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3d9cd9e..b84dfab 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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.
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 ? */