summaryrefslogtreecommitdiffstats
path: root/src/patchelf.cc
diff options
context:
space:
mode:
authorTuomas Tynkkynen <tuomas@tuxera.com>2017-04-19 14:22:23 (GMT)
committerTuomas Tynkkynen <tuomas@tuxera.com>2017-04-19 14:33:33 (GMT)
commitdaaffbe7f3e4e1ec0052f8d6ce153cd7f5fdeb76 (patch)
tree9c7835d0b5ec5babbfd27293f056f11034265223 /src/patchelf.cc
parentbfc3db32d26cbf6d1aa96aa0fd9a82aa5576ba17 (diff)
downloadpatchelf-daaffbe7f3e4e1ec0052f8d6ce153cd7f5fdeb76.zip
patchelf-daaffbe7f3e4e1ec0052f8d6ce153cd7f5fdeb76.tar.gz
patchelf-daaffbe7f3e4e1ec0052f8d6ce153cd7f5fdeb76.tar.bz2
Give a better error message if the file lacks a section header table
Currently, patchelf outputs this when run on a UPX-compressed ELF file: patchelf: patchelf.cc:420: ElfFile<Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym, Elf_Verneed>::ElfFile(FileContents): Assertion `shstrtabIndex < shdrs.size()' failed. Make it give a nicer error message: patchelf: no section headers. The input file is probably a statically linked, self-decompressing binary Fixes #63
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r--src/patchelf.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 6363395..86195fb 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -392,10 +392,13 @@ ElfFile<ElfFileParamNames>::ElfFile(FileContents fileContents)
error("wrong ELF type");
if ((size_t) (rdi(hdr->e_phoff) + rdi(hdr->e_phnum) * rdi(hdr->e_phentsize)) > fileContents->size())
- error("missing program headers");
+ error("program header table out of bounds");
+
+ if (rdi(hdr->e_shnum) == 0)
+ error("no section headers. The input file is probably a statically linked, self-decompressing binary");
if ((size_t) (rdi(hdr->e_shoff) + rdi(hdr->e_shnum) * rdi(hdr->e_shentsize)) > fileContents->size())
- error("missing section headers");
+ error("section header table out of bounds");
if (rdi(hdr->e_phentsize) != sizeof(Elf_Phdr))
error("program headers have wrong size");