This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Fix illegal memory accesses in readelf when parsing a corrupt binary.
- From: Nick Clifton <nickc at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 17 Feb 2017 16:00:23 -0000
- Subject: [binutils-gdb] Fix illegal memory accesses in readelf when parsing a corrupt binary.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b814a36d3440de95f2ac6eaa4fc7935c322ea456
commit b814a36d3440de95f2ac6eaa4fc7935c322ea456
Author: Nick Clifton <nickc@redhat.com>
Date: Fri Feb 17 15:59:45 2017 +0000
Fix illegal memory accesses in readelf when parsing a corrupt binary.
PR binutils/21156
* readelf.c (find_section_in_set): Test for invalid section
indicies.
Diff:
---
binutils/ChangeLog | 6 ++++++
binutils/readelf.c | 10 ++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 07c7aa9..9ae381f 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,5 +1,11 @@
2017-02-17 Nick Clifton <nickc@redhat.com>
+ PR binutils/21156
+ * readelf.c (find_section_in_set): Test for invalid section
+ indicies.
+
+2017-02-17 Nick Clifton <nickc@redhat.com>
+
* readelf.c (get_section_type_name): Add decoding of GNU section
types.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index ea9da7a..20df6f8 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -676,8 +676,14 @@ find_section_in_set (const char * name, unsigned int * set)
if (set != NULL)
{
while ((i = *set++) > 0)
- if (streq (SECTION_NAME (section_headers + i), name))
- return section_headers + i;
+ {
+ /* See PR 21156 for a reproducer. */
+ if (i >= elf_header.e_shnum)
+ continue; /* FIXME: Should we issue an error message ? */
+
+ if (streq (SECTION_NAME (section_headers + i), name))
+ return section_headers + i;
+ }
}
return find_section (name);