readelf: Fix off by one sanity check in handle_gnu_hash.
authorMark Wielaard <mark@klomp.org>
Fri, 24 Mar 2017 11:15:02 +0000 (12:15 +0100)
committerMark Wielaard <mark@klomp.org>
Mon, 3 Apr 2017 21:40:41 +0000 (23:40 +0200)
We sanity check to make sure we don't index outside the chain array
by testing inner > max_nsyms. But inner is a zero-based index, while
max_nsyms is the maximum number. Change the check to inner >= max_nsyms.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c

index 0601198..9dd76c0 100644 (file)
@@ -1,3 +1,8 @@
+2017-03-24  Mark Wielaard  <mjw@redhat.com>
+
+       * readelf.c (handle_gnu_hash): Check inner < max_nsyms before
+       indexing into chain array.
+
 2017-02-16  Ulf Hermann  <ulf.hermann@qt.io>
 
        * addr2line.c: Include printversion.h
index 8d96ba3..490b6d5 100644 (file)
@@ -3263,7 +3263,7 @@ handle_gnu_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx)
            ++nsyms;
            if (maxlength < ++lengths[cnt])
              ++maxlength;
-           if (inner > max_nsyms)
+           if (inner >= max_nsyms)
              goto invalid_data;
          }
        while ((chain[inner++] & 1) == 0);