]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
unstrip: Robustify gelf_getshdr and gelf_getsymshndx calls.
authorMark Wielaard <mark@klomp.org>
Sun, 28 Apr 2019 16:07:03 +0000 (18:07 +0200)
committerMark Wielaard <mark@klomp.org>
Sun, 28 Apr 2019 16:07:51 +0000 (18:07 +0200)
Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/unstrip.c

index e3e411ef50807fc1bf7316317b461243fc40ea25..ae1379327483e5b53a8728808139d11c5b98a2b2 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-28  Mark Wielaard  <mark@klomp.org>
+
+       * unstrip.c (add_new_section_symbols): Call ELF_CHECK after
+       gelf_getsymshndx.
+       (new_shstrtab): Call ELF_CHECK after gelf_getshdr.
+
 2019-04-28  Mark Wielaard  <mark@klomp.org>
 
        * size.c (show_sysv): Call INTERNAL_ERROR if gelf_getshdr
index 3495b1d916eb5edee95811a240413f89afbe2817..fc87832550b38f250d6a71a4967afe8519d222c7 100644 (file)
@@ -644,6 +644,7 @@ add_new_section_symbols (Elf_Scn *old_symscn, size_t old_shnum,
       GElf_Word shndx = SHN_UNDEF;
       GElf_Sym *sym = gelf_getsymshndx (old_symdata, shndxdata,
                                        i, &sym_mem, &shndx);
+      ELF_CHECK (sym != NULL, _("cannot get symbol table entry: %s"));
       ELF_CHECK (gelf_update_symshndx (symdata, shndxdata, i,
                                       sym, shndx),
                 _("cannot update symbol table: %s"));
@@ -677,6 +678,7 @@ add_new_section_symbols (Elf_Scn *old_symscn, size_t old_shnum,
       GElf_Word shndx = SHN_UNDEF;
       GElf_Sym *sym = gelf_getsymshndx (old_symdata, shndxdata,
                                        i, &sym_mem, &shndx);
+      ELF_CHECK (sym != NULL, _("cannot get symbol table entry: %s"));
       ELF_CHECK (gelf_update_symshndx (symdata, shndxdata,
                                       i + added, sym, shndx),
                 _("cannot update symbol table: %s"));
@@ -1326,6 +1328,7 @@ new_shstrtab (Elf *unstripped, size_t unstripped_shnum,
        Elf_Scn *scn = elf_getscn (unstripped, i + 1);
        GElf_Shdr shdr_mem;
        GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+       ELF_CHECK (shdr != NULL, _("cannot get section header: %s"));
        const char *name = get_section_name (i + 1, shdr, shstrtab);
        unstripped_strent[i] = dwelf_strtab_add (strtab, name);
        ELF_CHECK (unstripped_strent[i] != NULL,
@@ -1349,6 +1352,7 @@ new_shstrtab (Elf *unstripped, size_t unstripped_shnum,
        Elf_Scn *scn = elf_getscn (unstripped, i + 1);
        GElf_Shdr shdr_mem;
        GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+       ELF_CHECK (shdr != NULL, _("cannot get section header: %s"));
        shdr->sh_name = dwelf_strent_off (unstripped_strent[i]);
        if (i + 1 == unstripped_shstrndx)
          shdr->sh_size = strtab_data->d_size;