mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-03 19:15:30 +00:00
llvm-readobj: Handle invalid references to the string table.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fc41ae8496
commit
fa1a4b2275
BIN
test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64
Executable file
BIN
test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64
Executable file
Binary file not shown.
@ -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
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user