Skip to content

Commit bf03aff

Browse files
committed
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.
1 parent e6b9f43 commit bf03aff

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/patchelf.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,16 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
835835
debug("rewriting symbol table section %d\n", i);
836836
for (size_t entry = 0; (entry + 1) * sizeof(Elf_Sym) <= rdi(shdrs[i].sh_size); entry++) {
837837
Elf_Sym * sym = (Elf_Sym *) (contents + rdi(shdrs[i].sh_offset) + entry * sizeof(Elf_Sym));
838-
if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE) {
839-
string section = sectionsByOldIndex[rdi(sym->st_shndx)];
838+
unsigned int shndx = rdi(sym->st_shndx);
839+
if (shndx != SHN_UNDEF && shndx < SHN_LORESERVE) {
840+
if (shndx >= sectionsByOldIndex.size()) {
841+
fprintf(stderr, "warning: entry %d in symbol table refers to a non-existent section, skipping\n", shndx);
842+
continue;
843+
}
844+
string section = sectionsByOldIndex.at(shndx);
840845
assert(!section.empty());
841846
unsigned int newIndex = findSection3(section); // inefficient
842-
//debug("rewriting symbol %d: index = %d (%s) -> %d\n", entry, rdi(sym->st_shndx), section.c_str(), newIndex);
847+
//debug("rewriting symbol %d: index = %d (%s) -> %d\n", entry, shndx, section.c_str(), newIndex);
843848
wri(sym->st_shndx, newIndex);
844849
}
845850
}

0 commit comments

Comments
 (0)