summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2018-01-05 12:07:09 (GMT)
committerGitHub <noreply@github.com>2018-01-05 12:07:09 (GMT)
commitaceb96e9a8698e8bd0c6295939d217489bd26ef9 (patch)
treec15783ce07fb49394d4a0ee4769abcdcc5022c0d /src
parent840eb0ecbb032abdb98bcc83fc95b3fc4ea02ada (diff)
parentdaaffbe7f3e4e1ec0052f8d6ce153cd7f5fdeb76 (diff)
downloadpatchelf-aceb96e9a8698e8bd0c6295939d217489bd26ef9.zip
patchelf-aceb96e9a8698e8bd0c6295939d217489bd26ef9.tar.gz
patchelf-aceb96e9a8698e8bd0c6295939d217489bd26ef9.tar.bz2
Merge pull request #121 from dezgeg/better-error-messages
Better error messages when run on statically-linked (or otherwise weird) binaries
Diffstat (limited to 'src')
-rw-r--r--src/patchelf.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 55b38e3..0e9aeb7 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -394,10 +394,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");
@@ -559,8 +562,12 @@ template<ElfFileParams>
Elf_Shdr & ElfFile<ElfFileParamNames>::findSection(const SectionName & sectionName)
{
Elf_Shdr * shdr = findSection2(sectionName);
- if (!shdr)
- error("cannot find section '" + sectionName + "'");
+ if (!shdr) {
+ std::string extraMsg = "";
+ if (sectionName == ".interp" || sectionName == ".dynamic" || sectionName == ".dynstr")
+ extraMsg = ". The input file is most likely statically linked";
+ error("cannot find section '" + sectionName + "'" + extraMsg);
+ }
return *shdr;
}