]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: elf_getdata should not adjust alignment for SHT_NOBITS sections.
authorMark Wielaard <mjw@redhat.com>
Thu, 4 Feb 2016 08:53:41 +0000 (09:53 +0100)
committerMark Wielaard <mjw@redhat.com>
Wed, 10 Feb 2016 10:27:18 +0000 (11:27 +0100)
In commit c0748e "libelf: More checking of valid sh_addralign values." we
adjusted bogus alignment of data buffers if they were greater than the
offset of the data in the file. This works OK, except when there is no
data in the file. So make sure to not adjust any NOBITS sections.

Also adds a test that shows the issue and makes sure elflint is called
with --gnu in run-strip-test.sh.

https://bugzilla.redhat.com/show_bug.cgi?id=1303845

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/elf_getdata.c
tests/ChangeLog
tests/Makefile.am
tests/run-strip-nobitsalign.sh [new file with mode: 0755]
tests/run-strip-test.sh
tests/testfile-nobitsalign.bz2 [new file with mode: 0755]
tests/testfile-nobitsalign.strip.bz2 [new file with mode: 0755]

index afe6a6a5e9c4e11c5b689c02661fca09fa583cca..ec56b53479ea68dcfc1b59f2bc46d10e45ac200c 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-04  Mark Wielaard  <mjw@redhat.com>
+
+       * elf_getdata.c (__libelf_set_rawdata_wrlock): Don't adjust align
+       for SHT_NOBITS sections.
+
 2016-01-22  Chih-Hung Hsieh <chh@google.com>
 
        * elf_compress.c (__libelf_compress): Move nested function
index 4ec94b980bb1880ee973a03682f7dda09f502380..d1fafbfe758c95bd50af29b586e20b896e2d606f 100644 (file)
@@ -1,5 +1,5 @@
 /* Return the next data element from the section after possibly converting it.
-   Copyright (C) 1998-2005, 2006, 2007, 2015 Red Hat, Inc.
+   Copyright (C) 1998-2005, 2006, 2007, 2015, 2016 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 1998.
 
@@ -363,7 +363,7 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
      at least an ehdr this will only trigger for alignment values > 64
      which should be uncommon.  */
   align = align ?: 1;
-  if (align > offset)
+  if (type != SHT_NOBITS && align > offset)
     align = offset;
   scn->rawdata.d.d_align = align;
   if (elf->class == ELFCLASS32
index 37f981126440c9ac6108cc83bafb4a05617f1d32..a043ade6de3d4579bc5bd0504bcdc6fbc00ed2a7 100644 (file)
@@ -1,3 +1,13 @@
+2016-02-04  Mark Wielaard  <mjw@redhat.com>
+
+       * run-strip-nobitsalign.sh: New test.
+       * testfile-nobitsalign.bz2: New testfile.
+       * testfile-nobitsalign.strip.bz2: Likewise.
+       * Makefile.am (TESTS): Add run-strip-nobitsalign.sh.
+       (EXTRA_DIST): Add run-strip-nobitsalign.sh, testfile-nobitsalign.bz2
+       and testfile-nobitsalign.strip.bz2.
+       * run-strip-test.sh: Add --gnu to elflint calls.
+
 2016-01-13  Mark Wielaard  <mjw@redhat.com>
 
        * dwfl-bug-fd-leak.c: Skip test unless on __linux__.
index 7b9e108394eab2cc5c65c7d99a690a5a4ebc69de..f3e7c01cacb63a308f545bb1eb5da8a951535d3c 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 1996-2015 Red Hat, Inc.
+## Copyright (C) 1996-2016 Red Hat, Inc.
 ## This file is part of elfutils.
 ##
 ## This file is free software; you can redistribute it and/or modify
@@ -80,6 +80,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
        run-strip-test6.sh run-strip-test7.sh run-strip-test8.sh \
        run-strip-test9.sh run-strip-test10.sh \
        run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \
+       run-strip-nobitsalign.sh \
        run-unstrip-test.sh run-unstrip-test2.sh \
        run-unstrip-test3.sh run-unstrip-M.sh run-elfstrmerge-test.sh \
        run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \
@@ -163,6 +164,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \
             run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \
             run-strip-test9.sh run-strip-test10.sh run-strip-strmerge.sh \
+            run-strip-nobitsalign.sh \
+            testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \
             run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \
             hello_ppc64.ko.bz2 hello_s390.ko.bz2 hello_aarch64.ko.bz2 \
             run-unstrip-test.sh run-unstrip-test2.sh \
diff --git a/tests/run-strip-nobitsalign.sh b/tests/run-strip-nobitsalign.sh
new file mode 100755 (executable)
index 0000000..db9b1d9
--- /dev/null
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) Red Hat, Inc., 2016.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# static unsigned char buffer[4096] __attribute((aligned (4096)));
+# 
+# char
+# f (int i)
+# {
+#   return buffer[i];
+# }
+# 
+# int
+# main (int argc, char **argv)
+# {
+#   return buffer[argc] == 0;
+# }
+
+original=testfile-nobitsalign
+stripped=testfile-nobitsalign.strip
+
+. $srcdir/run-strip-test.sh
index 43d27e533c2f9e062d6b741f658b211c6551f899..42aa9888c5f6d20dd28d088f25da0750ad81395d 100755 (executable)
@@ -34,13 +34,13 @@ status=0
 cmp $stripped testfile.temp || status=$?
 
 # Check elflint and the expected result.
-testrun ${abs_top_builddir}/src/elflint -q testfile.temp || status=$?
+testrun ${abs_top_builddir}/src/elflint --gnu -q testfile.temp || status=$?
 
 test -z "$debugfile" || {
 cmp $debugfile testfile.debug.temp || status=$?
 
 # Check elflint and the expected result.
-testrun ${abs_top_builddir}/src/elflint -q -d testfile.debug.temp || status=$?
+testrun ${abs_top_builddir}/src/elflint --gnu -q -d testfile.debug.temp || status=$?
 
 # Now test unstrip recombining those files.
 testrun ${abs_top_builddir}/src/unstrip -o testfile.unstrip testfile.temp testfile.debug.temp
diff --git a/tests/testfile-nobitsalign.bz2 b/tests/testfile-nobitsalign.bz2
new file mode 100755 (executable)
index 0000000..7f0d424
Binary files /dev/null and b/tests/testfile-nobitsalign.bz2 differ
diff --git a/tests/testfile-nobitsalign.strip.bz2 b/tests/testfile-nobitsalign.strip.bz2
new file mode 100755 (executable)
index 0000000..f72000c
Binary files /dev/null and b/tests/testfile-nobitsalign.strip.bz2 differ