]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
unstrip: Fix off by one array access with unstripped_strent.
authorMark Wielaard <mjw@redhat.com>
Wed, 6 Jul 2016 19:31:54 +0000 (21:31 +0200)
committerMark Wielaard <mjw@redhat.com>
Mon, 11 Jul 2016 07:58:55 +0000 (09:58 +0200)
When configuring with --enable-sanitize-undefined the latest GCC found
an array out of bounds access when running the un-strip-strmerge.sh test.
We keep an array of section names. But skipped section zero, since it
didn't have a name. We should however not actually skip the first array
index (zero) when storing and reading the names.

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

index 21fc7d517b8cd131dfc7edbee68131d0a979efc2..fbe4afc51cc1457460716c7abcae436267c5687a 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-06  Mark Wielaard  <mjw@redhat.com>
+
+       * unstrip.c (copy_elided_sections): Use unstripped_strent[] from
+       index zero, instead of one.
+
 2016-06-28  Richard Henderson <rth@redhat.com>
 
        * elflint.c (valid_e_machine): Add EM_BPF.
index 85e0a1da79c5949ff637db2d4a3fed9462233a3a..adeb5991b24816211b86d52abe3acdf090025a6b 100644 (file)
@@ -1761,8 +1761,8 @@ more sections in stripped file than debug file -- arguments reversed?"));
              GElf_Shdr mem;
              GElf_Shdr *hdr = gelf_getshdr (sec, &mem);
              const char *name = get_section_name (i + 1, hdr, shstrtab);
-             unstripped_strent[i + 1] = ebl_strtabadd (symstrtab, name, 0);
-             ELF_CHECK (unstripped_strent[i + 1] != NULL,
+             unstripped_strent[i] = ebl_strtabadd (symstrtab, name, 0);
+             ELF_CHECK (unstripped_strent[i] != NULL,
                         _("cannot add section name to string table: %s"));
            }
 
@@ -1785,7 +1785,7 @@ more sections in stripped file than debug file -- arguments reversed?"));
              Elf_Scn *sec = elf_getscn (unstripped, i + 1);
              GElf_Shdr mem;
              GElf_Shdr *hdr = gelf_getshdr (sec, &mem);
-             shdr->sh_name = ebl_strtaboffset (unstripped_strent[i + 1]);
+             shdr->sh_name = ebl_strtaboffset (unstripped_strent[i]);
              update_shdr (sec, hdr);
            }
        }