[PATCH] D28502: [compiler-rt] [Interception] Properly check for export table's size before referring to its elements.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 30 10:34:52 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL293521: [interception] Check for export table's size before referring to its elements. (authored by mpividori).

Changed prior to commit:
  https://reviews.llvm.org/D28502?vs=86245&id=86309#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28502

Files:
  compiler-rt/trunk/lib/interception/interception_win.cc
  compiler-rt/trunk/lib/interception/tests/interception_win_test.cc


Index: compiler-rt/trunk/lib/interception/tests/interception_win_test.cc
===================================================================
--- compiler-rt/trunk/lib/interception/tests/interception_win_test.cc
+++ compiler-rt/trunk/lib/interception/tests/interception_win_test.cc
@@ -613,6 +613,13 @@
   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
Index: compiler-rt/trunk/lib/interception/interception_win.cc
===================================================================
--- compiler-rt/trunk/lib/interception/interception_win.cc
+++ compiler-rt/trunk/lib/interception/interception_win.cc
@@ -878,6 +878,8 @@
 
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28502.86309.patch
Type: text/x-patch
Size: 1355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170130/ed7b3f35/attachment.bin>


More information about the llvm-commits mailing list