summaryrefslogtreecommitdiffstats
path: root/src/readelf.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2014-11-22 23:08:48 +0100
committerMark Wielaard <[email protected]>2014-11-26 20:17:22 +0100
commit712c8faddc08844fb1f2814c8b6e817f03b0698e (patch)
treedf68a29bd32a009875438dfbbd68cbe6f30425c0 /src/readelf.c
parent2deeb7c51020df07d752107cdc6822d70ae1da4e (diff)
Use elf_getphdrnum instead of accessing ehdr->e_phnum directly.
Using elf_getphdrnum lets us handle ELF files that use more than PN_XNUM phdrs. And guards against some corrupt files. Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'src/readelf.c')
-rw-r--r--src/readelf.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/src/readelf.c b/src/readelf.c
index 08de7989..3b1f035a 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -835,11 +835,6 @@ process_elf_file (Dwfl_Module *dwflmod, int fd)
gettext ("cannot determine number of program headers: %s"),
elf_errmsg (-1));
- /* If there isn't actually a program header then set phnum to zero.
- Don't do any extra work. gelf_getphdr will always return NULL. */
- if (ehdr->e_phoff == 0)
- phnum = 0;
-
/* For an ET_REL file, libdwfl has adjusted the in-core shdrs
and may have applied relocation to some sections.
So we need to get a fresh Elf handle on the file to display those. */
@@ -1162,7 +1157,7 @@ There are %d section headers, starting at offset %#" PRIx64 ":\n\
static void
print_phdr (Ebl *ebl, GElf_Ehdr *ehdr)
{
- if (ehdr->e_phnum == 0 || ehdr->e_phoff == 0)
+ if (phnum == 0)
/* No program header, this is OK in relocatable objects. */
return;