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.
This commit is contained in:
Nick Clifton 2017-02-17 15:59:45 +00:00
parent 1b4b80bf37
commit b814a36d34
2 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,9 @@
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> 2017-02-17 Nick Clifton <nickc@redhat.com>
* readelf.c (get_section_type_name): Add decoding of GNU section * readelf.c (get_section_type_name): Add decoding of GNU section

View File

@ -676,8 +676,14 @@ find_section_in_set (const char * name, unsigned int * set)
if (set != NULL) if (set != NULL)
{ {
while ((i = *set++) > 0) 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); return find_section (name);