[ASan/Win tests] Add more DLL tests

llvm-svn: 208893
This commit is contained in:
Timur Iskhodzhanov 2014-05-15 15:13:06 +00:00
parent bdf1cd374f
commit 5910d6d126
6 changed files with 139 additions and 13 deletions

View File

@ -11,12 +11,12 @@ int test_function() {
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T0 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
// CHECK: test_function {{.*}}dll_malloc_left_oob.cc:[[@LINE-3]] // CHECK: test_function {{.*}}dll_malloc_left_oob.cc:[[@LINE-3]]
// CHECK: main {{.*}}dll_host.cc // CHECK-NEXT: main {{.*}}dll_host.cc
// CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region // CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region
// CHECK-LABEL: allocated by thread T0 here: // CHECK-LABEL: allocated by thread T0 here:
// CHECK: malloc // CHECK: malloc
// CHECK: test_function {{.*}}dll_malloc_left_oob.cc:[[@LINE-9]] // CHECK: test_function {{.*}}dll_malloc_left_oob.cc:[[@LINE-9]]
// CHECK: main {{.*}}dll_host.cc // CHECK-NEXT: main {{.*}}dll_host.cc
// CHECK-LABEL: SUMMARY // CHECK-LABEL: SUMMARY
free(buffer); free(buffer);
return 0; return 0;

View File

@ -13,15 +13,15 @@ int test_function() {
// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T0 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-3]] // CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-3]]
// CHECK: main {{.*}}dll_host // CHECK-NEXT: main {{.*}}dll_host
// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region // CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
// CHECK-LABEL: freed by thread T0 here: // CHECK-LABEL: freed by thread T0 here:
// CHECK: free // CHECK: free
// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-9]] // CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-9]]
// CHECK: main {{.*}}dll_host // CHECK-NEXT: main {{.*}}dll_host
// CHECK-LABEL: previously allocated by thread T0 here: // CHECK-LABEL: previously allocated by thread T0 here:
// CHECK: malloc // CHECK: malloc
// CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-14]] // CHECK: test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-14]]
// CHECK: main {{.*}}dll_host // CHECK-NEXT: main {{.*}}dll_host
return 0; return 0;
} }

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}