summaryrefslogtreecommitdiffstats
path: root/src/patchelf.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r--src/patchelf.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index cfa39e2..118dbb0 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -135,8 +135,11 @@ private:
ElfFile * elfFile;
bool operator ()(const Elf_Phdr & x, const Elf_Phdr & y)
{
- if (x.p_type == PT_PHDR) return true;
+ // A PHDR comes before everything else.
if (y.p_type == PT_PHDR) return false;
+ if (x.p_type == PT_PHDR) return true;
+
+ // Sort non-PHDRs by address.
return elfFile->rdi(x.p_paddr) < elfFile->rdi(y.p_paddr);
}
};
@@ -394,10 +397,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 +565,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;
}