This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Fix seg-fault running strip on a corrupt binary.
- From: Nick Clifton <nickc at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 5 Dec 2016 13:11:38 -0000
- Subject: [binutils-gdb] Fix seg-fault running strip on a corrupt binary.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=88add6d8e794073758b5398c52bbb76ab40a2923
commit 88add6d8e794073758b5398c52bbb76ab40a2923
Author: Nick Clifton <nickc@redhat.com>
Date: Mon Dec 5 13:11:01 2016 +0000
Fix seg-fault running strip on a corrupt binary.
PR ld/20923
* objcopy.c (mark_symbols_used_in_relocations): Check for a null
symbol pointer before attempting to mark the symbol as kept.
Diff:
---
binutils/ChangeLog | 6 ++++++
binutils/objcopy.c | 4 +++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index cf54b0f..bfb1804 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-05 Nick Clifton <nickc@redhat.com>
+
+ PR ld/20923
+ * objcopy.c (mark_symbols_used_in_relocations): Check for a null
+ symbol pointer before attempting to mark the symbol as kept.
+
2016-12-01 Luis Machado <lgustavo@codesourcery.com>
* nm.c (sort_symbols_by_size): Don't read symbol size if symbol
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 4910fcf..6a398ce 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3551,7 +3551,9 @@ mark_symbols_used_in_relocations (bfd *ibfd, sec_ptr isection, void *symbolsarg)
special bfd section symbols, then mark it with BSF_KEEP. */
for (i = 0; i < relcount; i++)
{
- if (*relpp[i]->sym_ptr_ptr != bfd_com_section_ptr->symbol
+ /* See PR 20923 for a reproducer for the NULL test. */
+ if (relpp[i]->sym_ptr_ptr != NULL
+ && *relpp[i]->sym_ptr_ptr != bfd_com_section_ptr->symbol
&& *relpp[i]->sym_ptr_ptr != bfd_abs_section_ptr->symbol
&& *relpp[i]->sym_ptr_ptr != bfd_und_section_ptr->symbol)
(*relpp[i]->sym_ptr_ptr)->flags |= BSF_KEEP;