1 | // RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t |
2 | // RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll |
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; |
12 | // CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]] |
13 | // CHECK: WRITE of size 1 at [[ADDR]] thread T1 |
14 | // CHECK-NEXT: thread_proc{{.*}}dll_thread_stack_array_left_oob.cpp:[[@LINE-3]] |
15 | // |
16 | // CHECK: Address [[ADDR]] is located in stack of thread T1 at offset [[OFFSET:.*]] in frame |
17 | // CHECK-NEXT: thread_proc{{.*}}dll_thread_stack_array_left_oob.cpp |
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: |
28 | // CHECK: test_function{{.*}}dll_thread_stack_array_left_oob.cpp:[[@LINE-2]] |
29 | // CHECK-NEXT: main{{.*}}dll_host.cpp |
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 | } |
37 | |