bfd_size_type dynamic_size;
unsigned int dynamic_nent;
char *dynamic_strings;
+unsigned long dynamic_strings_length;
char *string_table;
unsigned long string_table_length;
unsigned long num_dynamic_syms;
(is_32bit_elf ? get_32bit_elf_symbols (file, section) \
: get_64bit_elf_symbols (file, section))
-
+#define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
+/* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
+ already been called and verified that the string exists. */
+#define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
+\f
static void
error (const char *message, ...)
{
Elf_Internal_Sym *symtab,
unsigned long nsyms,
char *strtab,
+ unsigned long strtablen,
int is_rela)
{
unsigned int i;
print_symbol (22, sec_name);
}
else if (strtab == NULL)
- printf (_("<string table index %3ld>"), psym->st_name);
+ printf (_("<string table index: %3ld>"), psym->st_name);
+ else if (psym->st_name > strtablen)
+ printf (_("<corrupt string table index: %3ld>"), psym->st_name);
else
print_symbol (22, strtab + psym->st_name);
dynamic_strings = get_data (NULL, file, section->sh_offset,
section->sh_size, _("dynamic strings"));
+ dynamic_strings_length = section->sh_size;
}
else if (section->sh_type == SHT_SYMTAB_SHNDX)
{
offset_from_vma (file, rel_offset, rel_size),
rel_size,
dynamic_symbols, num_dynamic_syms,
- dynamic_strings, is_rela);
+ dynamic_strings, dynamic_strings_length, is_rela);
}
}
if (rel_size)
{
Elf_Internal_Shdr *strsec;
- Elf_Internal_Sym *symtab;
- char *strtab;
int is_rela;
- unsigned long nsyms;
printf (_("\nRelocation section "));
printf (_(" at offset 0x%lx contains %lu entries:\n"),
rel_offset, (unsigned long) (rel_size / section->sh_entsize));
- symtab = NULL;
- strtab = NULL;
- nsyms = 0;
+ is_rela = section->sh_type == SHT_RELA;
+
if (section->sh_link)
{
Elf_Internal_Shdr *symsec;
-
+ Elf_Internal_Sym *symtab;
+ unsigned long nsyms;
+ unsigned long strtablen;
+ char *strtab = NULL;
+
symsec = SECTION_HEADER (section->sh_link);
nsyms = symsec->sh_size / symsec->sh_entsize;
symtab = GET_ELF_SYMBOLS (file, symsec);
strtab = get_data (NULL, file, strsec->sh_offset,
strsec->sh_size, _("string table"));
- }
- is_rela = section->sh_type == SHT_RELA;
+ strtablen = strtab == NULL ? 0 : strsec->sh_size;
- dump_relocations (file, rel_offset, rel_size,
- symtab, nsyms, strtab, is_rela);
-
- if (strtab)
- free (strtab);
- if (symtab)
- free (symtab);
+ dump_relocations (file, rel_offset, rel_size,
+ symtab, nsyms, strtab, strtablen, is_rela);
+ if (strtab)
+ free (strtab);
+ free (symtab);
+ }
+ else
+ dump_relocations (file, rel_offset, rel_size,
+ NULL, 0, NULL, 0, is_rela);
found = 1;
}
break;
case DT_MIPS_IVERSION:
- if (dynamic_strings != NULL)
- printf ("Interface Version: %s\n",
- dynamic_strings + entry->d_un.d_val);
+ if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
+ printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
else
- printf ("%ld\n", (long) entry->d_un.d_ptr);
+ printf ("<corrupt: %ld>\n", (long) entry->d_un.d_ptr);
break;
case DT_MIPS_TIME_STAMP:
dynamic_strings = get_data (NULL, file, offset, str_tab_len,
_("dynamic string table"));
+ dynamic_strings_length = str_tab_len;
break;
}
}
break;
}
- if (dynamic_strings)
- printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
+ if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
+ printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
else
{
printf (": ");
{
char *name;
- if (dynamic_strings == NULL)
- name = NULL;
+ if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
+ name = GET_DYNAMIC_NAME (entry->d_un.d_val);
else
- name = dynamic_strings + entry->d_un.d_val;
+ name = NULL;
if (name)
{
case DT_FINI_ARRAY:
if (do_dynamic)
{
- if (dynamic_strings != NULL && entry->d_tag == DT_USED)
+ if (entry->d_tag == DT_USED
+ && VALID_DYNAMIC_NAME (entry->d_un.d_val))
{
- char *name;
-
- name = dynamic_strings + entry->d_un.d_val;
+ char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);
if (*name)
{
aux.vda_name = BYTE_GET (eaux->vda_name);
aux.vda_next = BYTE_GET (eaux->vda_next);
- if (dynamic_strings)
- printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
+ if (VALID_DYNAMIC_NAME (aux.vda_name))
+ printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
else
printf (_("Name index: %ld\n"), aux.vda_name);
aux.vda_name = BYTE_GET (eaux->vda_name);
aux.vda_next = BYTE_GET (eaux->vda_next);
- if (dynamic_strings)
+ if (VALID_DYNAMIC_NAME (aux.vda_name))
printf (_(" %#06x: Parent %d: %s\n"),
- isum, j, dynamic_strings + aux.vda_name);
+ isum, j, GET_DYNAMIC_NAME (aux.vda_name));
else
printf (_(" %#06x: Parent %d, name index: %ld\n"),
isum, j, aux.vda_name);
printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
- if (dynamic_strings)
- printf (_(" File: %s"), dynamic_strings + ent.vn_file);
+ if (VALID_DYNAMIC_NAME (ent.vn_file))
+ printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
else
printf (_(" File: %lx"), ent.vn_file);
aux.vna_name = BYTE_GET (eaux->vna_name);
aux.vna_next = BYTE_GET (eaux->vna_next);
- if (dynamic_strings)
+ if (VALID_DYNAMIC_NAME (aux.vna_name))
printf (_(" %#06x: Name: %s"),
- isum, dynamic_strings + aux.vna_name);
+ isum, GET_DYNAMIC_NAME (aux.vna_name));
else
printf (_(" %#06x: Name index: %lx"),
isum, aux.vna_name);
printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
- print_symbol (25, dynamic_strings + psym->st_name);
+ if (VALID_DYNAMIC_NAME (psym->st_name))
+ print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
+ else
+ printf (" <corrupt: %14ld>", psym->st_name);
putchar ('\n');
}
}
unsigned short int flags = dynamic_syminfo[i].si_flags;
printf ("%4d: ", i);
- print_symbol (30, dynamic_strings + dynamic_symbols[i].st_name);
+ if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
+ print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
+ else
+ printf ("<corrupt: %19ld>", dynamic_symbols[i].st_name);
putchar (' ');
switch (dynamic_syminfo[i].si_boundto)
break;
default:
if (dynamic_syminfo[i].si_boundto > 0
- && dynamic_syminfo[i].si_boundto < dynamic_nent)
+ && dynamic_syminfo[i].si_boundto < dynamic_nent
+ && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
{
- print_symbol (10,
- dynamic_strings
- + (dynamic_section
- [dynamic_syminfo[i].si_boundto].d_un.d_val));
+ print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
putchar (' ' );
}
else
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf ("%3lu: ", (unsigned long) cnt);
- print_symbol (20, dynamic_strings + liblist.l_name);
+ if (VALID_DYNAMIC_NAME (liblist.l_name))
+ print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
+ else
+ printf ("<corrupt: %9ld>", liblist.l_name);
printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
liblist.l_version);
printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
print_vma (psym->st_value, FULL_HEX);
putchar (' ');
- print_symbol (25, dynamic_strings + psym->st_name);
+ if (VALID_DYNAMIC_NAME (psym->st_name))
+ print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
+ else
+ printf ("<corrupt: %14ld>", psym->st_name);
putchar ('\n');
}
{
free (dynamic_strings);
dynamic_strings = NULL;
+ dynamic_strings_length = 0;
}
if (dynamic_symbols)