From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============9189429512621355442==" MIME-Version: 1.0 From: Mark Wielaard To: elfutils-devel@lists.fedorahosted.org Subject: [PATCH] elflint: Fix sh_entsize check when comparing SHT_HASH and SHT_GNU_HASH. Date: Tue, 09 Feb 2016 16:24:06 +0100 Message-ID: <1455031446-29062-1-git-send-email-mjw@redhat.com> --===============9189429512621355442== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable GCC6 -Wduplicated-cond found the following issue: elflint.c: In function =E2=80=98compare_hash_gnu_hash=E2=80=99: elflint.c:2483:34: error: duplicated =E2=80=98if=E2=80=99 condition [-Werro= r=3Dduplicated-cond] else if (hash_shdr->sh_entsize =3D=3D sizeof (Elf64_Word)) ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ elflint.c:2448:29: note: previously used here if (hash_shdr->sh_entsize =3D=3D 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 --- src/ChangeLog | 6 ++++++ src/elflint.c | 4 ++-- tests/ChangeLog | 6 ++++++ tests/Makefile.am | 1 + tests/run-elflint-test.sh | 9 ++++++++- tests/testfile-s390x-hash-both.bz2 | Bin 0 -> 2435 bytes 6 files changed, 23 insertions(+), 3 deletions(-) create mode 100755 tests/testfile-s390x-hash-both.bz2 diff --git a/src/ChangeLog b/src/ChangeLog index af98c4d..7dfab44 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2016-02-09 Mark Wielaard + + * 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-08 Mark Wielaard = * elfcompress.c (compress_section): Use %zu to print size_t. diff --git a/src/elflint.c b/src/elflint.c index 7a7b9ce..e27e692 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -2480,7 +2480,7 @@ hash section [%2zu] '%s' uses too much data\n"), } } } - else if (hash_shdr->sh_entsize =3D=3D sizeof (Elf64_Word)) + else if (hash_shdr->sh_entsize =3D=3D sizeof (Elf64_Xword)) { const Elf64_Xword *hasharr =3D (Elf64_Xword *) hash_data->d_buf; if (hash_data->d_size < 2 * sizeof (Elf32_Word)) @@ -2521,7 +2521,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; } = diff --git a/tests/ChangeLog b/tests/ChangeLog index defb8ae..04fe3a3 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2016-02-09 Mark Wielaard + + * testfile-s390x-hash-both.bz2: New testfile. + * Makefile.am (EXTRA_DIST): Add testfile-s390x-hash-both.bz2. + * run-elflint-test.sh: Add elflint testfile-s390x-hash-both test. + 2016-02-04 Mark Wielaard = * run-strip-nobitsalign.sh: New test. diff --git a/tests/Makefile.am b/tests/Makefile.am index f3e7c01..fedcb39 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -236,6 +236,7 @@ EXTRA_DIST =3D run-arextract.sh run-arsymtest.sh \ testfile56.bz2 testfile57.bz2 testfile58.bz2 \ run-typeiter.sh testfile59.bz2 \ run-readelf-d.sh testlib_dynseg.so.bz2 \ + testfile-s390x-hash-both.bz2 \ run-readelf-gdb_index.sh testfilegdbindex5.bz2 \ testfilegdbindex7.bz2 \ run-readelf-s.sh testfilebazdbg.bz2 testfilebazdyn.bz2 \ diff --git a/tests/run-elflint-test.sh b/tests/run-elflint-test.sh index 68615b9..f3bd901 100755 --- a/tests/run-elflint-test.sh +++ b/tests/run-elflint-test.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005, 2007, 2008 Red Hat, Inc. +# Copyright (C) 2005, 2007, 2008, 2015 Red Hat, Inc. # This file is part of elfutils. # Written by Ulrich Drepper , 2005. # @@ -40,4 +40,11 @@ testrun ${abs_top_builddir}/src/elflint -q testfile46 testfiles testlib_dynseg.so testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testlib_dynseg.so = +# s390x has SHT_HASH with sh_entsize 8 (really should be 4, but see common= .h) +# This was wrongly checked when comparing .gnu.hash and .hash. +# Simple "int main (int argc, char **argv) { return 0; }" +# gcc -Xlinker --hash-style=3Dboth -o testfile-s390x-hash-both s390x-hash-= both.c +testfiles testfile-s390x-hash-both +testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile-s390x-hash-bo= th + exit 0 diff --git a/tests/testfile-s390x-hash-both.bz2 b/tests/testfile-s390x-hash= -both.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..86e0bcc792da1aa7f74c78c6a3d= e13f3b75b3723 GIT binary patch literal 2435 zcmb7=3D=3D{FmQ0>u*{4H{ytgfT*j+MXq7=3Dg~=3DsG>A@$smPhST|Z;s>gim_(m>$$WYpo>j^n!J2M7rgv75UM9Ob^t1=3D`jaY(a)u<=3DsHq1tP-OsG zNjZU;k&i$iK=3D@c96N&~irZH#$6pC;|fD09dYoFvft03^V`%0I~tQG2jGKQ-vuu0%Ub&8Datk#77G(a)MSE|esRN=3DmDo;z!VgMAd&yX*{pg|b# zOg7-G7J&dKuz)2d|3|kZ5_0f4i$000_(2CYtT z$1lF4iDbP;7yYbp@)09_Wd)pciP|4gPX{huYw1Z(a)O;R^=3Dw1tfDH>Um6l3p|R(a)tqW> zIdWH2e%IV^ieSVr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