]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elflint: Correct gnu_symbias usage in compare_hash_gnu_hash.
authorMark Wielaard <mjw@redhat.com>
Mon, 9 Mar 2015 15:41:48 +0000 (16:41 +0100)
committerMark Wielaard <mjw@redhat.com>
Fri, 13 Mar 2015 08:41:25 +0000 (09:41 +0100)
commit 0a545e "elflint: Add various low-level checks." introduced a bug
in the handling of the gnu_symbias. The symbol in the bucket should first
be compared to STN_UNDEF before applying the bias. And the used symbol
index should have the bias added when compared against plain hash symbol.

Found on Debian wheezy with run-elflint-self.sh.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/elflint.c

index dad984edb541ffa954eedc6660e26f3eef2aa283..bb9580a85dfb1a9468faa15b93369067b43ce1ee 100644 (file)
@@ -1,3 +1,7 @@
+2015-03-09  Mark Wielaard  <mjw@redhat.com>
+
+       * elflint.c (compare_hash_gnu_hash): Correct gnu_symbias usage.
+
 2015-01-03  Mark Wielaard  <mjw@redhat.com>
 
        * elfcmp (main): Check section name is not NULL. Check sh_entsize
index 143424c6329bbbe062869152aace02b91f91d986..a6f9b688176c5a50516221eca90f892e56fa4393 100644 (file)
@@ -2397,20 +2397,22 @@ hash section [%2zu] '%s' uses too much data\n"),
 
   for (Elf32_Word cnt = 0; cnt < gnu_nbucket; ++cnt)
     {
-      Elf32_Word symidx = gnu_bucket[cnt] - gnu_symbias;;
-      if (symidx != STN_UNDEF)
-       do
-         {
-           if (symidx >= max_nsyms || symidx >= nentries)
-             {
-               ERROR (gettext ("\
-hash section [%2zu] '%s' invalid symbol index\n"),
-                      gnu_hash_idx, gnu_hash_name);
-               return;
-             }
-           used[symidx] |= 1;
-         }
-       while ((gnu_chain[symidx++] & 1u) == 0);
+      if (gnu_bucket[cnt] != STN_UNDEF)
+       {
+         Elf32_Word symidx = gnu_bucket[cnt] - gnu_symbias;
+         do
+           {
+             if (symidx >= max_nsyms || symidx + gnu_symbias >= nentries)
+               {
+                 ERROR (gettext ("\
+hash section [%2zu] '%s' invalid symbol index %" PRIu32 " (max_nsyms: %" PRIu32 ", nentries: %" PRIu32 "\n"),
+                        gnu_hash_idx, gnu_hash_name, symidx, max_nsyms, nentries);
+                 return;
+               }
+             used[symidx + gnu_symbias] |= 1;
+           }
+         while ((gnu_chain[symidx++] & 1u) == 0);
+       }
     }
 
   /* Now go over the old hash table and check that we cover the same