diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-01-14 11:05:44 (GMT) |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-01-14 11:05:44 (GMT) |
commit | bf03aff2ea0951bd9f74fe0a304b4d32141ee42e (patch) | |
tree | 36ac0b412b54806b85f2ceefe2d91f65fbcc87c2 /src/patchelf.cc | |
parent | e6b9f431e4d5c7122112812d905bb2f921afa939 (diff) | |
download | patchelf-bf03aff2ea0951bd9f74fe0a304b4d32141ee42e.zip patchelf-bf03aff2ea0951bd9f74fe0a304b4d32141ee42e.tar.gz patchelf-bf03aff2ea0951bd9f74fe0a304b4d32141ee42e.tar.bz2 |
Handle invalid symbol table entries that refer to non-existent sections
For instance, libcairo-swt.so from Eclipse SDK 4.2.2 has entries like:
30: 0000000000000000 0 SECTION LOCAL DEFAULT 30
even though there is no section 30. So ignore these.
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r-- | src/patchelf.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 1b7e510..a4591f1 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -835,11 +835,16 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress) debug("rewriting symbol table section %d\n", i); for (size_t entry = 0; (entry + 1) * sizeof(Elf_Sym) <= rdi(shdrs[i].sh_size); entry++) { Elf_Sym * sym = (Elf_Sym *) (contents + rdi(shdrs[i].sh_offset) + entry * sizeof(Elf_Sym)); - if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE) { - string section = sectionsByOldIndex[rdi(sym->st_shndx)]; + unsigned int shndx = rdi(sym->st_shndx); + if (shndx != SHN_UNDEF && shndx < SHN_LORESERVE) { + if (shndx >= sectionsByOldIndex.size()) { + fprintf(stderr, "warning: entry %d in symbol table refers to a non-existent section, skipping\n", shndx); + continue; + } + string section = sectionsByOldIndex.at(shndx); assert(!section.empty()); unsigned int newIndex = findSection3(section); // inefficient - //debug("rewriting symbol %d: index = %d (%s) -> %d\n", entry, rdi(sym->st_shndx), section.c_str(), newIndex); + //debug("rewriting symbol %d: index = %d (%s) -> %d\n", entry, shndx, section.c_str(), newIndex); wri(sym->st_shndx, newIndex); } } |