/* readelf.c -- display contents of an ELF format file
- Copyright (C) 1998, 99, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 99, 2000, 2001 Free Software Foundation, Inc.
Originally developed by Eric Youngdale <eric@andante.jic.com>
Modifications by Nick Clifton <nickc@cygnus.com>
unsigned int rela_size;
char * dynamic_strings;
char * string_table;
+unsigned long string_table_length;
unsigned long num_dynamic_syms;
Elf_Internal_Sym * dynamic_symbols;
Elf_Internal_Syminfo * dynamic_syminfo;
#endif
#define UNKNOWN -1
-#define SECTION_NAME(X) (string_table + (X)->sh_name)
+#define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
+ ((X)->sh_name >= string_table_length \
+ ? "<corrupt>" : string_table + (X)->sh_name))
#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
if (section->sh_size != 0)
{
- unsigned long string_table_offset;
-
- string_table_offset = section->sh_offset;
-
GET_DATA_ALLOC (section->sh_offset, section->sh_size,
string_table, char *, "string table");
+
+ string_table_length = section->sh_size;
}
/* Scan the sections for the dynamic symbol table
}
printf (_("\nSection '%s' contains %d entries:\n"),
- string_table + sect->sh_name, cnt);
+ SECTION_NAME (sect), cnt);
option = iopt;
{
free (string_table);
string_table = NULL;
+ string_table_length = 0;
}
if (dynamic_strings)