From bf03aff2ea0951bd9f74fe0a304b4d32141ee42e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Jan 2014 12:05:44 +0100 Subject: 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. --- src/patchelf.cc | 11 ++++++++--- 1 file 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::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); } } -- cgit v0.12