From 3bd2c2fe9051d15ea331827576395d927c5a12fc Mon Sep 17 00:00:00 2001 From: Timur Iskhodzhanov Date: Thu, 15 May 2014 14:27:46 +0000 Subject: [PATCH] [ASan/Win tests] Add the first DLL test llvm-svn: 208884 --- .../test/asan/TestCases/Windows/dll_host.cc | 37 +++++++++++++++++++ .../Windows/dll_malloc_left_oob_crash.cc | 23 ++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 compiler-rt/test/asan/TestCases/Windows/dll_host.cc create mode 100644 compiler-rt/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_host.cc b/compiler-rt/test/asan/TestCases/Windows/dll_host.cc new file mode 100644 index 000000000000..44eb611daf04 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/dll_host.cc @@ -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 +#include + +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; +} diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc b/compiler-rt/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc new file mode 100644 index 000000000000..8084337b061f --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc @@ -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 +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; +}