[llvm] r242658 - llvm-readobj: Handle invalid references to the string table.
Rafael Espindola
rafael.espindola at gmail.com
Sun Jul 19 20:38:18 PDT 2015
Author: rafael
Date: Sun Jul 19 22:38:17 2015
New Revision: 242658
URL: http://llvm.org/viewvc/llvm-project?rev=242658&view=rev
Log:
llvm-readobj: Handle invalid references to the string table.
Added:
llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64 (with props)
Modified:
llvm/trunk/test/Object/corrupt.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
llvm/trunk/tools/llvm-readobj/llvm-readobj.h
Added: llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64?rev=242658&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64 (added) and llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64 Sun Jul 19 22:38:17 2015 differ
Propchange: llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64
------------------------------------------------------------------------------
svn:executable = *
Modified: llvm/trunk/test/Object/corrupt.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/corrupt.test?rev=242658&r1=242657&r2=242658&view=diff
==============================================================================
--- llvm/trunk/test/Object/corrupt.test (original)
+++ llvm/trunk/test/Object/corrupt.test Sun Jul 19 22:38:17 2015
@@ -24,3 +24,10 @@ RUN: not llvm-readobj %p/Inputs/corrupt-
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
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=242658&r1=242657&r2=242658&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Sun Jul 19 22:38:17 2015
@@ -954,6 +954,14 @@ void printFlags(T Value, ArrayRef<EnumEn
}
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) {
switch (Type) {
@@ -1011,14 +1019,14 @@ static void printValue(const ELFFile<ELF
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>::printNeededLibrari
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());
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=242658&r1=242657&r2=242658&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Sun Jul 19 22:38:17 2015
@@ -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;
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.h?rev=242658&r1=242657&r2=242658&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.h (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.h Sun Jul 19 22:38:17 2015
@@ -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);
More information about the llvm-commits
mailing list