From: Nick Clifton Date: Tue, 18 Apr 2006 09:41:36 +0000 (+0000) Subject: PR 2257 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0b49d371230ed1a85925a509755c87a750e0447c;p=binutils-gdb.git PR 2257 * elfcode.h (elf_object_p): Allow files with corrupt e_shstrndx fields to still be handled as ELF files. * readelf.c (SECTION_NAME): Cope with a missing string table. (process_file_header): Cope with a corrupt e_shstrndx field. (process_section_headers): Correctly handle an e_shstrndx value of SHF_UNDEF. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index d6069baafbc..2938fa0fe45 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2006-04-18 Nick Clifton + + PR 2257 + * elfcode.h (elf_object_p): Allow files with corrupt e_shstrndx + fields to still be handled as ELF files. + 2006-04-16 Daniel Jacobowitz * po/SRC-POTFILES.in: Regenerated. diff --git a/bfd/elfcode.h b/bfd/elfcode.h index f7f85ba2056..9bb66e11c0c 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -742,9 +742,18 @@ elf_object_p (bfd *abfd) if (i_ehdrp->e_shstrndx >= elf_numsections (abfd) || (i_ehdrp->e_shstrndx >= SHN_LORESERVE && i_ehdrp->e_shstrndx <= SHN_HIRESERVE)) - goto got_wrong_format_error; + { + /* PR 2257: + We used to just goto got_wrong_format_error here + but there are binaries in existance for which this test + will prevent the binutils from working with them at all. + So we are kind, and reset the string index value to 0 + so that at least some processing can be done. */ + i_ehdrp->e_shstrndx = SHN_UNDEF; + _bfd_error_handler (_("warning: %s has a corrupt string table index - ignoring"), abfd->filename); + } } - else if (i_ehdrp->e_shstrndx != 0) + else if (i_ehdrp->e_shstrndx != SHN_UNDEF) goto got_wrong_format_error; /* Read in the program headers. */ diff --git a/binutils/ChangeLog b/binutils/ChangeLog index fdb3934a3d9..2f25dc99cae 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,11 @@ +2006-04-18 Nick Clifton + + PR 2257 + * readelf.c (SECTION_NAME): Cope with a missing string table. + (process_file_header): Cope with a corrupt e_shstrndx field. + (process_section_headers): Correctly handle an e_shstrndx value of + SHF_UNDEF. + 2006-04-12 Nick Clifton * objdump.c (objdump_symbol_at_address): Fix typo in comment. diff --git a/binutils/readelf.c b/binutils/readelf.c index d8bd54f440f..09f1d513cd7 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -222,9 +222,11 @@ static void (*byte_put) (unsigned char *, bfd_vma, int); #define UNKNOWN -1 -#define SECTION_NAME(X) ((X) == NULL ? "" : \ - ((X)->sh_name >= string_table_length \ - ? "" : string_table + (X)->sh_name)) +#define SECTION_NAME(X) \ + ((X) == NULL ? "" \ + : string_table == NULL ? "" \ + : ((X)->sh_name >= string_table_length ? "" \ + : string_table + (X)->sh_name)) /* Given st_shndx I, map to section_headers index. */ #define SECTION_HEADER_INDEX(I) \ @@ -3142,6 +3144,11 @@ process_file_header (void) (long) elf_header.e_shstrndx); if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX) printf (" (%ld)", (long) section_headers[0].sh_link); + else if (elf_header.e_shstrndx != SHN_UNDEF + && (elf_header.e_shstrndx >= elf_header.e_shnum + || (elf_header.e_shstrndx >= SHN_LORESERVE + && elf_header.e_shstrndx <= SHN_HIRESERVE))) + printf (" "); putc ('\n', stdout); } @@ -3151,6 +3158,11 @@ process_file_header (void) elf_header.e_shnum = section_headers[0].sh_size; if (elf_header.e_shstrndx == SHN_XINDEX) elf_header.e_shstrndx = section_headers[0].sh_link; + else if (elf_header.e_shstrndx != SHN_UNDEF + && (elf_header.e_shstrndx >= elf_header.e_shnum + || (elf_header.e_shstrndx >= SHN_LORESERVE + && elf_header.e_shstrndx <= SHN_HIRESERVE))) + elf_header.e_shstrndx = SHN_UNDEF; free (section_headers); section_headers = NULL; } @@ -3920,7 +3932,8 @@ process_section_headers (FILE *file) return 0; /* Read in the string table, so that we have names to display. */ - if (SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum) + if (elf_header.e_shstrndx != SHN_UNDEF + && SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum) { section = SECTION_HEADER (elf_header.e_shstrndx);