Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t |
| 2 | // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | // RUN: not %run %t %t.dll 2>&1 | FileCheck %s |
| 4 | |
| 5 | #include <windows.h> |
| 6 | #include <malloc.h> |
| 7 | |
| 8 | DWORD WINAPI thread_proc(void *context) { |
| 9 | int subscript = -1; |
| 10 | char stack_buffer[42]; |
| 11 | stack_buffer[subscript] = 42; |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 12 | // CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | // CHECK: WRITE of size 1 at [[ADDR]] thread T1 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 14 | // CHECK-NEXT: thread_proc{{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-3]] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 15 | // |
| 16 | // CHECK: Address [[ADDR]] is located in stack of thread T1 at offset [[OFFSET:.*]] in frame |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 17 | // CHECK-NEXT: thread_proc{{.*}}dll_thread_stack_array_left_oob.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 18 | // |
| 19 | // CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] underflows this variable |
| 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | extern "C" __declspec(dllexport) |
| 25 | int test_function() { |
| 26 | HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL); |
| 27 | // CHECK-LABEL: Thread T1 created by T0 here: |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 28 | // CHECK: test_function{{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-2]] |
| 29 | // CHECK-NEXT: main{{.*}}dll_host.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 30 | // CHECK-LABEL: SUMMARY |
| 31 | if (thr == 0) |
| 32 | return 1; |
| 33 | if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE)) |
| 34 | return 2; |
| 35 | return 0; |
| 36 | } |