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 <malloc.h>
6
7 extern "C" __declspec(dllexport)
test_function()8 int test_function() {
9 int *buffer = (int*)malloc(42);
10 free(buffer);
11 buffer[0] = 42;
12 // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
13 // CHECK: WRITE of size 4 at [[ADDR]] thread T0
14 // CHECK-NEXT: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-3]]
15 // CHECK-NEXT: main {{.*}}dll_host
16 //
17 // CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
18 // CHECK-LABEL: freed by thread T0 here:
19 // CHECK-NEXT: free
20 // CHECK-NEXT: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-10]]
21 // CHECK-NEXT: main {{.*}}dll_host
22 //
23 // CHECK-LABEL: previously allocated by thread T0 here:
24 // CHECK-NEXT: malloc
25 // CHECK-NEXT: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-16]]
26 // CHECK-NEXT: main {{.*}}dll_host
27 return 0;
28 }
29