diff options
author | Mark Wielaard <mjw@redhat.com> | 2016-02-09 14:18:49 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2016-02-15 23:45:19 +0100 |
commit | f4dc76404ce8116b806550d7515ec98be953df9e (patch) | |
tree | 0b3726e266f8cc6f71c1f24d105217c9d1e5370a /src | |
parent | 22035605b9da4a6ee07385c0e7715fe8d35488a4 (diff) | |
download | elfutils-f4dc76404ce8116b806550d7515ec98be953df9e.tar.gz |
elflint: Fix sh_entsize check when comparing SHT_HASH and SHT_GNU_HASH.
GCC6 -Wduplicated-cond found the following issue:
elflint.c: In function ‘compare_hash_gnu_hash’:
elflint.c:2483:34: error: duplicated ‘if’ condition [-Werror=duplicated-cond]
else if (hash_shdr->sh_entsize == sizeof (Elf64_Word))
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
elflint.c:2448:29: note: previously used here
if (hash_shdr->sh_entsize == sizeof (Elf32_Word))
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Which is correct, a Word in both Elf32 and Elf64 files is 4 bytes.
We meant to check for sizeof (Elf64_Xword) which is 8 bytes.
Also fix the section index and name in the error message.
The reason we probably didn't see this issue before is that SHT_HASH
sections really always should have sh_entsize of 4 even on 64bit arches.
There are however a couple of arches with mistakes in their sysv ABI.
See libelf/common.h. This also would only be triggered if on such an
architectures when the ELF file would have both a SHT_HASH and SHT_GNU_HASH
section and elflint would try to compare those sections.
Add an example testfile-s390x-hash-both to run-elflint-test.sh.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 6 | ||||
-rw-r--r-- | src/elflint.c | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 707c2717..e4b17d62 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2016-02-09 Mark Wielaard <mjw@redhat.com> + + * elflint.c (compare_hash_gnu_hash): Check hash sh_entsize against + sizeof (Elf64_Xword). Correct invalid sh_entsize error message + section idx and name. + 2016-01-13 Mark Wielaard <mjw@redhat.com> * elflint.c (check_elf_header): Recognize ELFOSABI_FREEBSD. diff --git a/src/elflint.c b/src/elflint.c index eae77614..15b12f6f 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -2482,7 +2482,7 @@ hash section [%2zu] '%s' uses too much data\n"), } } } - else if (hash_shdr->sh_entsize == sizeof (Elf64_Word)) + else if (hash_shdr->sh_entsize == sizeof (Elf64_Xword)) { const Elf64_Xword *hasharr = (Elf64_Xword *) hash_data->d_buf; if (hash_data->d_size < 2 * sizeof (Elf32_Word)) @@ -2523,7 +2523,7 @@ hash section [%2zu] '%s' uses too much data\n"), { ERROR (gettext ("\ hash section [%2zu] '%s' invalid sh_entsize\n"), - gnu_hash_idx, gnu_hash_name); + hash_idx, hash_name); return; } |