[compiler-rt] r208884 - [ASan/Win tests] Add the first DLL test

Timur Iskhodzhanov timurrrr at google.com
Thu May 15 07:27:46 PDT 2014


Author: timurrrr
Date: Thu May 15 09:27:46 2014
New Revision: 208884

URL: http://llvm.org/viewvc/llvm-project?rev=208884&view=rev
Log:
[ASan/Win tests] Add the first DLL test

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_host.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc

Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_host.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_host.cc?rev=208884&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_host.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_host.cc Thu May 15 09:27:46 2014
@@ -0,0 +1,37 @@
+// This is a host program for DLL tests.
+//
+// Just make sure we can compile this.
+// The actual compile&run sequence is to be done by the DLL tests.
+// RUN: %clangxx_asan -O0 %s -Fe%t
+
+#include <stdio.h>
+#include <windows.h>
+
+int main(int argc, char **argv) {
+  if (argc != 2) {
+    printf("Usage: %s [client].dll\n", argv[0]);
+    return 101;
+  }
+
+  const char *dll_name = argv[1];
+
+  HMODULE h = LoadLibrary(dll_name);
+  if (!h) {
+    printf("Could not load DLL: %s (code: %lu)!\n",
+           dll_name, GetLastError());
+    return 102;
+  }
+
+  typedef int (*test_function)();
+  test_function gf = (test_function)GetProcAddress(h, "test_function");
+  if (!gf) {
+    printf("Could not locate test_function in the DLL!\n");
+    FreeLibrary(h);
+    return 103;
+  }
+
+  int ret = gf();
+
+  FreeLibrary(h);
+  return ret;
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc?rev=208884&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc Thu May 15 09:27:46 2014
@@ -0,0 +1,23 @@
+// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// FIXME: 'cat' is needed due to PR19744.
+// RUN: not %run %t %t.dll 2>&1 | cat | FileCheck %s
+
+#include <malloc.h>
+extern "C" __declspec(dllexport)
+int test_function() {
+  char *buffer = (char*)malloc(42);
+  buffer[-1] = 42;
+// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK:   test_function {{.*}}dll_malloc_left_oob_crash.cc:[[@LINE-3]]
+// CHECK:   main {{.*}}dll_host.cc
+// CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region
+// CHECK-LABEL: allocated by thread T0 here:
+// CHECK:   malloc
+// CHECK:   test_function {{.*}}dll_malloc_left_oob_crash.cc:[[@LINE-9]]
+// CHECK:   main {{.*}}dll_host.cc
+// CHECK-LABEL: SUMMARY
+  free(buffer);
+  return 0;
+}





More information about the llvm-commits mailing list