From: Nick Clifton Date: Fri, 17 Feb 2017 15:59:45 +0000 (+0000) Subject: Fix illegal memory accesses in readelf when parsing a corrupt binary. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b814a36d3440de95f2ac6eaa4fc7935c322ea456;p=binutils-gdb.git 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 --git a/binutils/ChangeLog b/binutils/ChangeLog index 07c7aa964e8..9ae381fd81f 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2017-02-17 Nick Clifton + + PR binutils/21156 + * readelf.c (find_section_in_set): Test for invalid section + indicies. + 2017-02-17 Nick Clifton * readelf.c (get_section_type_name): Add decoding of GNU section diff --git a/binutils/readelf.c b/binutils/readelf.c index ea9da7afb79..20df6f89960 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);