From: Petr Machata Date: Thu, 17 Mar 2011 12:17:35 +0000 (+0100) Subject: dwarflint: More thorough validation of ELF sections X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc69d5d8136f4615aa238d2f0eb355e7e48710c2;p=thirdparty%2Felfutils.git dwarflint: More thorough validation of ELF sections --- diff --git a/dwarflint/sections.cc b/dwarflint/sections.cc index d5736c4be..4a8f6401e 100644 --- a/dwarflint/sections.cc +++ b/dwarflint/sections.cc @@ -250,12 +250,7 @@ namespace REALLOC (file, sec); file->sec[file->size++].id = sec_invalid; - bool check_rel = true; - - /* Try to obtain .shstrtab, which we will need in following. If - we fail, elf is broken. */ - Elf_Scn *shstrscn = elf_getscn (elf, file->ehdr.e_shstrndx); - if (shstrscn == NULL || elf_rawdata (shstrscn, NULL) == NULL) + if (false) { invalid_elf: wr_error () << "Broken ELF: " << elf_errmsg (-1) << "." @@ -263,6 +258,11 @@ namespace goto close_and_out; } + /* Check that the ELF file is sound. */ + for (Elf_Scn *scn = NULL; (scn = elf_nextscn (elf, scn)); ) + if (elf_rawdata (scn, NULL) == NULL) + goto invalid_elf; + for (Elf_Scn *scn = NULL; (scn = elf_nextscn (elf, scn)); ) { REALLOC (file, sec); @@ -366,7 +366,7 @@ namespace if (it->second.secndx != 0) file->debugsec[it->second.id] = file->sec + it->second.secndx; - if (check_rel) + if (true) { Elf_Data *reloc_symdata = NULL; if (reloc_symtab != NULL)