[compiler-rt] r208893 - [ASan/Win tests] Add more DLL tests
Timur Iskhodzhanov
timurrrr at google.com
Thu May 15 08:13:07 PDT 2014
Author: timurrrr
Date: Thu May 15 10:13:06 2014
New Revision: 208893
URL: http://llvm.org/viewvc/llvm-project?rev=208893&view=rev
Log:
[ASan/Win tests] Add more DLL tests
Added:
compiler-rt/trunk/test/asan/TestCases/Windows/dll_noreturn.cc
compiler-rt/trunk/test/asan/TestCases/Windows/dll_poison_unpoison.cc
compiler-rt/trunk/test/asan/TestCases/Windows/dll_stack_use_after_return.cc
compiler-rt/trunk/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
Modified:
compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc
compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc
Modified: compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc?rev=208893&r1=208892&r2=208893&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc Thu May 15 10:13:06 2014
@@ -10,13 +10,13 @@ int test_function() {
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.cc:[[@LINE-3]]
-// CHECK: main {{.*}}dll_host.cc
+// CHECK: test_function {{.*}}dll_malloc_left_oob.cc:[[@LINE-3]]
+// CHECK-NEXT: 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.cc:[[@LINE-9]]
-// CHECK: main {{.*}}dll_host.cc
+// CHECK: malloc
+// CHECK: test_function {{.*}}dll_malloc_left_oob.cc:[[@LINE-9]]
+// CHECK-NEXT: main {{.*}}dll_host.cc
// CHECK-LABEL: SUMMARY
free(buffer);
return 0;
Modified: compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc?rev=208893&r1=208892&r2=208893&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc Thu May 15 10:13:06 2014
@@ -12,16 +12,16 @@ int test_function() {
buffer[0] = 42;
// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
-// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-3]]
-// CHECK: main {{.*}}dll_host
+// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-3]]
+// CHECK-NEXT: main {{.*}}dll_host
// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
// CHECK-LABEL: freed by thread T0 here:
-// CHECK: free
-// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-9]]
-// CHECK: main {{.*}}dll_host
+// CHECK: free
+// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-9]]
+// CHECK-NEXT: main {{.*}}dll_host
// CHECK-LABEL: previously allocated by thread T0 here:
-// CHECK: malloc
-// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-14]]
-// CHECK: main {{.*}}dll_host
+// CHECK: malloc
+// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-14]]
+// CHECK-NEXT: main {{.*}}dll_host
return 0;
}
Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_noreturn.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_noreturn.cc?rev=208893&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_noreturn.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_noreturn.cc Thu May 15 10:13:06 2014
@@ -0,0 +1,28 @@
+// 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 <process.h>
+
+void noreturn_f() {
+ int subscript = -1;
+ char buffer[42];
+ buffer[subscript] = 42;
+ _exit(1);
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK: noreturn_f {{.*}}dll_noreturn.cc:[[@LINE-4]]
+// CHECK-NEXT: test_function {{.*}}dll_noreturn.cc
+// CHECK-NEXT: main {{.*}}dll_host.cc
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
+// CHECK-NEXT: noreturn_f {{.*}}dll_noreturn.cc
+// CHECK: 'buffer' <== Memory access at offset [[OFFSET]] underflows this variable
+// CHECK-LABEL: SUMMARY
+}
+
+extern "C" __declspec(dllexport)
+int test_function() {
+ noreturn_f();
+ return 0;
+}
Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_poison_unpoison.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_poison_unpoison.cc?rev=208893&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_poison_unpoison.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_poison_unpoison.cc Thu May 15 10:13:06 2014
@@ -0,0 +1,35 @@
+// 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 <sanitizer/asan_interface.h>
+
+void should_not_crash(volatile char *c) {
+ *c = 42;
+}
+
+void should_crash(volatile char *c) {
+ *c = 42;
+}
+
+extern "C" __declspec(dllexport)
+int test_function() {
+ char buffer[256];
+ should_not_crash(&buffer[0]);
+ __asan_poison_memory_region(buffer, 128);
+ should_not_crash(&buffer[192]);
+ __asan_unpoison_memory_region(buffer, 64);
+ should_not_crash(&buffer[32]);
+
+ should_crash(&buffer[96]);
+// CHECK: AddressSanitizer: use-after-poison on address [[ADDR:0x[0-9a-f]+]]
+// CHECK-NEXT: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK: should_crash {{.*}}\dll_poison_unpoison.cc
+// CHECK-NEXT: test_function {{.*}}\dll_poison_unpoison.cc:[[@LINE-4]]
+// CHECK-NEXT: main
+// CHECK: [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
+// CHECK-NEXT: test_function {{.*}}\dll_poison_unpoison.cc
+// CHECK: 'buffer' <== Memory access at offset [[OFFSET]] is inside this variable
+ return 0;
+}
Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_stack_use_after_return.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_stack_use_after_return.cc?rev=208893&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_stack_use_after_return.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_stack_use_after_return.cc Thu May 15 10:13:06 2014
@@ -0,0 +1,28 @@
+// 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: ASAN_OPTIONS=detect_stack_use_after_return=1 not %run %t %t.dll 2>&1 | cat | FileCheck %s
+
+#include <malloc.h>
+
+char *x;
+
+void foo() {
+ char stack_buffer[42];
+ x = &stack_buffer[13];
+}
+
+extern "C" __declspec(dllexport)
+int test_function() {
+ foo();
+ *x = 42;
+// CHECK: AddressSanitizer: stack-use-after-return
+// CHECK: WRITE of size 1 at [[ADDR:.*]] thread T0
+// CHECK: test_function {{.*}}dll_stack_use_after_return.cc:[[@LINE-3]]
+// CHECK-NEXT: main
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
+// CHECK-NEXT: #0 {{.*}} foo {{.*}}dll_stack_use_after_return.cc
+// CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] is inside this variable
+ return 0;
+}
+
Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc?rev=208893&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc Thu May 15 10:13:06 2014
@@ -0,0 +1,35 @@
+// 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 <windows.h>
+#include <malloc.h>
+
+DWORD WINAPI thread_proc(void *context) {
+ int subscript = -1;
+ char stack_buffer[42];
+ stack_buffer[subscript] = 42;
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T1
+// CHECK: thread_proc {{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-3]]
+// CHECK: Address [[ADDR]] is located in stack of thread T1 at offset [[OFFSET:.*]] in frame
+// CHECK: thread_proc {{.*}}dll_thread_stack_array_left_oob.cc
+// CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] underflows this variable
+
+ return 0;
+}
+
+extern "C" __declspec(dllexport)
+int test_function() {
+ HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL);
+// CHECK-LABEL: Thread T1 created by T0 here:
+// CHECK: test_function {{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-2]]
+// CHECK-NEXT: main {{.*}}dll_host.cc
+// CHECK-LABEL: SUMMARY
+ if (thr == 0)
+ return 1;
+ if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE))
+ return 2;
+ return 0;
+}
More information about the llvm-commits
mailing list