[compiler-rt] r293521 - [interception] Check for export table's size before referring to its elements.
Marcos Pividori via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 30 10:23:37 PST 2017
Author: mpividori
Date: Mon Jan 30 12:23:37 2017
New Revision: 293521
URL: http://llvm.org/viewvc/llvm-project?rev=293521&view=rev
Log:
[interception] Check for export table's size before referring to its elements.
This fix a bug, when calling InternalGetProcAddress() for an executable that
doesn't export any symbol. So the table is empty.
If we don't check for this condition, the program fails with Error 0xc0000142.
Also, I add a regression test for Windows.
Differential Revision: https://reviews.llvm.org/D28502
Modified:
compiler-rt/trunk/lib/interception/interception_win.cc
compiler-rt/trunk/lib/interception/tests/interception_win_test.cc
Modified: compiler-rt/trunk/lib/interception/interception_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_win.cc?rev=293521&r1=293520&r2=293521&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/interception_win.cc (original)
+++ compiler-rt/trunk/lib/interception/interception_win.cc Mon Jan 30 12:23:37 2017
@@ -878,6 +878,8 @@ uptr InternalGetProcAddress(void *module
IMAGE_DATA_DIRECTORY *export_directory =
&headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT];
+ if (export_directory->Size == 0)
+ return 0;
RVAPtr<IMAGE_EXPORT_DIRECTORY> exports(module,
export_directory->VirtualAddress);
RVAPtr<DWORD> functions(module, exports->AddressOfFunctions);
Modified: compiler-rt/trunk/lib/interception/tests/interception_win_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_win_test.cc?rev=293521&r1=293520&r2=293521&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/tests/interception_win_test.cc (original)
+++ compiler-rt/trunk/lib/interception/tests/interception_win_test.cc Mon Jan 30 12:23:37 2017
@@ -613,6 +613,13 @@ TEST(Interception, PatchableFunctionPadd
EXPECT_FALSE(TestFunctionPatching(kUnpatchableCode6, override, prefix));
}
+TEST(Interception, EmptyExportTable) {
+ // We try to get a pointer to a function from an executable that doesn't
+ // export any symbol (empty export table).
+ uptr FunPtr = InternalGetProcAddress((void *)GetModuleHandleA(0), "example");
+ EXPECT_EQ(0U, FunPtr);
+}
+
} // namespace __interception
#endif // SANITIZER_WINDOWS
More information about the llvm-commits
mailing list