Compare commits

...

1 Commits

Author SHA1 Message Date
H.J. Lu
0860f6373e Check corrupted symbol table
bfd/

	PR binutils/12639
	* elfcode.h (elf_slurp_symbol_table): Check corrupted global
	symbols.

binutils/

	PR binutils/12639
	* readelf.c (process_symbol_table): Detect corrupted symbol
	table.
2017-11-26 09:38:09 -08:00
2 changed files with 24 additions and 1 deletions

View File

@@ -1173,6 +1173,9 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic)
sym = symbase = NULL;
else
{
/* Start of global symbols */
Elf_Internal_Sym *start_global;
isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
NULL, NULL, NULL);
if (isymbuf == NULL)
@@ -1218,6 +1221,9 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic)
if (xver != NULL)
++xver;
isymend = isymbuf + symcount;
start_global = isymbuf;
if (!elf_bad_symtab (abfd))
start_global += hdr->sh_info;
for (isym = isymbuf + 1, sym = symbase; isym < isymend; isym++, sym++)
{
memcpy (&sym->internal_elf_sym, isym, sizeof (Elf_Internal_Sym));
@@ -1275,6 +1281,12 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic)
if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
sym->symbol.value -= sym->symbol.section->vma;
if (isym < start_global
&& ELF_ST_BIND (isym->st_info) != STB_LOCAL)
(*_bfd_error_handler)
(_("%s: corrupted global symbol `%s' treated as local"),
abfd->filename, sym->symbol.name);
switch (ELF_ST_BIND (isym->st_info))
{
case STB_LOCAL:

View File

@@ -11571,6 +11571,12 @@ process_symbol_table (Filedata * filedata)
&& filedata->section_headers != NULL)
{
unsigned int i;
/* Irix 5 and 6 are broken. Object file symbol tables are not
always sorted correctly such that local symbols precede global
symbols, and the sh_info field in the symbol table is not
always right. */
bfd_boolean check_corrupt_symtab
= filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_IRIX;
for (i = 0, section = filedata->section_headers;
i < filedata->file_header.e_shnum;
@@ -11640,7 +11646,12 @@ process_symbol_table (Filedata * filedata)
putchar (' ');
print_vma (psym->st_size, DEC_5);
printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
if (check_corrupt_symtab
&& si < section->sh_info
&& ELF_ST_BIND (psym->st_info) != STB_LOCAL)
printf (" %-6s", "<corrupt>");
else
printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
else