]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elflint: Support checking ELF files with compressed sections.
authorMark Wielaard <mark@klomp.org>
Wed, 5 Apr 2017 15:09:27 +0000 (17:09 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 5 Apr 2017 15:09:27 +0000 (17:09 +0200)
Simply unconditionally uncompress any section to make sure indexes between
sections check out. Add some testcases with various compressed sections.

https://sourceware.org/bugzilla/show_bug.cgi?id=21332

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/elflint.c
tests/ChangeLog
tests/run-elflint-self.sh
tests/run-elflint-test.sh
tests/test-subr.sh

index e022503b52aed39faada661e7c31e69f4b7c52ef..a1bec198d41bb52162e9fd4b00be4a32377cf97b 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-05  Mark Wielaard  <mark@klomp.org>
+
+       * elflint.c (check_elf_header): Decompress all sections.
+
 2017-03-28  Mark Wielaard  <mark@klomp.org>
 
        * elflint (check_group): Don't check if there is no flag word.
index e0c65b6a53216a01f5147b40a0ff4a259e8f85d2..51e53c23c5eeef318c9d87066dd87371d963540d 100644 (file)
@@ -456,7 +456,9 @@ invalid number of section header table entries\n"));
        ERROR (gettext ("invalid section header index\n"));
     }
 
-  /* Check the shdrs actually exist. */
+  /* Check the shdrs actually exist.  And uncompress them before
+     further checking.  Indexes between sections reference the
+     uncompressed data.  */
   unsigned int scnt;
   Elf_Scn *scn = NULL;
   for (scnt = 1; scnt < shnum; ++scnt)
@@ -464,6 +466,9 @@ invalid number of section header table entries\n"));
        scn = elf_nextscn (ebl->elf, scn);
        if (scn == NULL)
          break;
+       /* If the section wasn't compressed this does nothing, but
+          returns an error.  We don't care.  */
+       elf_compress (scn, 0, 0);
      }
   if (scnt < shnum)
     ERROR (gettext ("Can only check %u headers, shnum was %u\n"), scnt, shnum);
index 3479cf0724abccb082fa7bdd2fc234ef8eb47993..5f7bcddbdef7b6f75d0ab16c356399bf36acf704 100644 (file)
@@ -1,3 +1,9 @@
+2017-04-05  Mark Wielaard  <mark@klomp.org>
+
+       * test-subr.sh (testrun_on_self_compressed): New function.
+       * run-elflint-self.sh: Call testrun_on_self_compressed.
+       * run-elflint-test.sh: Add testfile42z and testfile-s390x-hash-bothz.
+
 2017-03-30  Mark Wielaard  <mark@klomp.org>
 
        * peel_type.c: New file.
index 013109dbb1584eb6f5095cad5e9226db9572cc7e..58fa7d0fb21260d38fdca493e45f2dd6a840e5a5 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2005, 2007 Red Hat, Inc.
+# Copyright (C) 2005, 2007, 2017 Red Hat, Inc.
 # This file is part of elfutils.
 # Written by Ulrich Drepper <drepper@redhat.com>, 2005.
 #
@@ -19,3 +19,4 @@
 . $srcdir/test-subr.sh
 
 testrun_on_self ${abs_top_builddir}/src/elflint --quiet --gnu-ld
+testrun_on_self_compressed ${abs_top_builddir}/src/elflint --quiet --gnu-ld
index f3bd9012cd44352a84402441a45e865afadec591..caf172a616319b37ab2e9f828754aaf88680cc17 100755 (executable)
@@ -33,6 +33,11 @@ testrun ${abs_top_builddir}/src/elflint -q testfile33
 testfiles testfile42
 testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile42
 
+# Contains debuginfo, compress it, recheck
+tempfiles testfile42z
+testrun ${abs_top_builddir}/src/elfcompress -f -q -o testfile42z testfile42
+testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile42z
+
 testfiles testfile46
 testrun ${abs_top_builddir}/src/elflint -q testfile46
 
@@ -47,4 +52,9 @@ testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testlib_dynseg.so
 testfiles testfile-s390x-hash-both
 testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile-s390x-hash-both
 
+# Compress the symtab/strtab just because and recheck
+tempfiles testfile-s390x-hash-bothz
+testrun ${abs_top_builddir}/src/elfcompress -f -q --name='.s??tab' -o testfile-s390x-hash-bothz testfile-s390x-hash-both
+testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile-s390x-hash-bothz
+
 exit 0
index f397aed1a64776599d3c9c5ebc22ba36ba4a9fe9..a765db6395e9764c95dbdc2a270ee7ebfc1280f7 100644 (file)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2005-2015 Red Hat, Inc.
+# Copyright (C) 2005-2015, 2017 Red Hat, Inc.
 # This file is part of elfutils.
 #
 # This file is free software; you can redistribute it and/or modify
@@ -139,6 +139,24 @@ testrun_on_self()
   if test $exit_status != 0; then exit $exit_status; fi
 }
 
+# Compress the files first. Compress both debug sections and symtab.
+testrun_on_self_compressed()
+{
+  exit_status=0
+
+  for file in $self_test_files; do
+      tempfiles ${file}z
+      testrun ${abs_top_builddir}/src/elfcompress -f -q -o ${file}z ${file}
+      testrun ${abs_top_builddir}/src/elfcompress -f -q --name='.s??tab' ${file}z
+
+      testrun $* ${file}z \
+         || { echo "*** failure in $* ${file}z"; exit_status=1; }
+  done
+
+  # Only exit if something failed
+  if test $exit_status != 0; then exit $exit_status; fi
+}
+
 # Same as above, but redirects stdout to /dev/null
 testrun_on_self_quiet()
 {