llvm-readobj: Handle invalid references to the string table.

llvm-svn: 242658
This commit is contained in:
Rafael Espindola 2015-07-20 03:38:17 +00:00
parent c46ffb7a49
commit 00ddb1416d
5 changed files with 23 additions and 7 deletions

Binary file not shown.

View File

@ -24,3 +24,10 @@ RUN: not llvm-readobj %p/Inputs/corrupt-version.elf-x86_64 -dt \
RUN: 2>&1 | FileCheck --check-prefix=VER %s
VER: Error reading file: Invalid data was encountered while parsing the file.
// The file is missing the dynamic string table but has references to it.
RUN: not llvm-readobj -dynamic-table %p/Inputs/corrupt-invalid-strtab.elf.x86-64 \
RUN: 2>&1 | FileCheck --check-prefix=STRTAB %s
STRTAB: Invalid dynamic string table reference

View File

@ -953,6 +953,14 @@ void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) {
}
}
template <class ELFT>
static const char *getDynamicString(const ELFFile<ELFT> &O, uint64_t Value) {
const char *Ret = O.getDynamicString(Value);
if (!Ret)
reportError("Invalid dynamic string table reference");
return Ret;
}
template <class ELFT>
static void printValue(const ELFFile<ELFT> *O, uint64_t Type, uint64_t Value,
bool Is64, raw_ostream &OS) {
@ -1011,14 +1019,14 @@ static void printValue(const ELFFile<ELFT> *O, uint64_t Type, uint64_t Value,
OS << Value << " (bytes)";
break;
case DT_NEEDED:
OS << "SharedLibrary (" << O->getDynamicString(Value) << ")";
OS << "SharedLibrary (" << getDynamicString(*O, Value) << ")";
break;
case DT_SONAME:
OS << "LibrarySoname (" << O->getDynamicString(Value) << ")";
OS << "LibrarySoname (" << getDynamicString(*O, Value) << ")";
break;
case DT_RPATH:
case DT_RUNPATH:
OS << O->getDynamicString(Value);
OS << getDynamicString(*O, Value);
break;
case DT_MIPS_FLAGS:
printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS);
@ -1088,7 +1096,7 @@ void ELFDumper<ELFT>::printNeededLibraries() {
for (const auto &Entry : Obj->dynamic_table())
if (Entry.d_tag == ELF::DT_NEEDED)
Libs.push_back(Obj->getDynamicString(Entry.d_un.d_val));
Libs.push_back(getDynamicString(*Obj, Entry.d_un.d_val));
std::stable_sort(Libs.begin(), Libs.end());

View File

@ -188,14 +188,14 @@ namespace opts {
} // namespace opts
static void reportError(Twine Msg) {
namespace llvm {
void reportError(Twine Msg) {
outs() << Msg << "\n";
outs().flush();
exit(1);
}
namespace llvm {
void error(std::error_code EC) {
if (!EC)
return;

View File

@ -19,6 +19,7 @@ namespace llvm {
}
// Various helper functions.
void reportError(Twine Msg);
void error(std::error_code ec);
bool relocAddressLess(object::RelocationRef A,
object::RelocationRef B);