diff options
author | Mark Wielaard <mjw@redhat.com> | 2014-11-22 23:08:48 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2014-11-26 20:17:22 +0100 |
commit | 712c8faddc08844fb1f2814c8b6e817f03b0698e (patch) | |
tree | df68a29bd32a009875438dfbbd68cbe6f30425c0 /backends | |
parent | 2deeb7c51020df07d752107cdc6822d70ae1da4e (diff) | |
download | elfutils-712c8faddc08844fb1f2814c8b6e817f03b0698e.tar.gz |
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 <mjw@redhat.com>
Diffstat (limited to 'backends')
-rw-r--r-- | backends/ChangeLog | 7 | ||||
-rw-r--r-- | backends/ppc64_symbol.c | 3 | ||||
-rw-r--r-- | backends/ppc_symbol.c | 16 |
3 files changed, 18 insertions, 8 deletions
diff --git a/backends/ChangeLog b/backends/ChangeLog index abd22bf8..db1b1298 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,10 @@ +2014-11-22 Mark Wielaard <mjw@redhat.com> + + * ppc64_symbol.c (ppc64_bss_plt_p): Remove ehdr argument. + * ppc_symbol.c (find_dyn_got): Likewise. Use elf_getphdrnum. + (ppc_check_special_symbol): Call find_dyn_got without ehdr. + (ppc_bss_plt_p): Remove ehdr argument. + 2014-11-17 Mark Wielaard <mjw@redhat.com> * ppc64_init.c (ppc64_init): Check section name is not NULL. diff --git a/backends/ppc64_symbol.c b/backends/ppc64_symbol.c index 5a020d8d..0feddcee 100644 --- a/backends/ppc64_symbol.c +++ b/backends/ppc64_symbol.c @@ -108,8 +108,7 @@ ppc64_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, /* Check if backend uses a bss PLT in this file. */ bool -ppc64_bss_plt_p (Elf *elf __attribute__ ((unused)), - GElf_Ehdr *ehdr __attribute__ ((unused))) +ppc64_bss_plt_p (Elf *elf __attribute__ ((unused))) { return true; } diff --git a/backends/ppc_symbol.c b/backends/ppc_symbol.c index 220f243e..c17ab374 100644 --- a/backends/ppc_symbol.c +++ b/backends/ppc_symbol.c @@ -1,5 +1,5 @@ /* PPC specific symbolic name handling. - Copyright (C) 2004, 2005, 2007 Red Hat, Inc. + Copyright (C) 2004, 2005, 2007, 2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <drepper@redhat.com>, 2004. @@ -81,9 +81,13 @@ ppc_dynamic_tag_check (int64_t tag) /* Look for DT_PPC_GOT. */ static bool -find_dyn_got (Elf *elf, GElf_Ehdr *ehdr, GElf_Addr *addr) +find_dyn_got (Elf *elf, GElf_Addr *addr) { - for (int i = 0; i < ehdr->e_phnum; ++i) + size_t phnum; + if (elf_getphdrnum (elf, &phnum) != 0) + return false; + + for (size_t i = 0; i < phnum; ++i) { GElf_Phdr phdr_mem; GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem); @@ -127,7 +131,7 @@ ppc_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym, { /* In -msecure-plt mode, DT_PPC_GOT is present and must match. */ GElf_Addr gotaddr; - if (find_dyn_got (elf, ehdr, &gotaddr)) + if (find_dyn_got (elf, &gotaddr)) return sym->st_value == gotaddr; /* In -mbss-plt mode, any place in the section is valid. */ @@ -154,8 +158,8 @@ ppc_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym, /* Check if backend uses a bss PLT in this file. */ bool -ppc_bss_plt_p (Elf *elf, GElf_Ehdr *ehdr) +ppc_bss_plt_p (Elf *elf) { GElf_Addr addr; - return ! find_dyn_got (elf, ehdr, &addr); + return ! find_dyn_got (elf, &addr); } |