xref: /llvm-project/compiler-rt/test/asan/TestCases/Windows/malloc_uaf.cpp (revision 53a81d4d26f0409de8a0655d7af90f2bea222a12)
1 // RUN: %clang_cl_asan %Od %s %Fe%t
2 // RUN: not %run %t 2>&1 | FileCheck %s
3 
4 #include <malloc.h>
5 
6 int main() {
7   char *buffer = (char*)malloc(42);
8   free(buffer);
9   buffer[0] = 42;
10   // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
11   // CHECK: WRITE of size 1 at [[ADDR]] thread T0
12   // CHECK-NEXT: {{#0 .* main .*malloc_uaf.cpp}}:[[@LINE-3]]
13   // CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
14   // CHECK: freed by thread T0 here:
15   // CHECK-NEXT: {{#0 .* free }}
16   // CHECK: {{ #[1-3] .* main .*malloc_uaf.cpp}}:[[@LINE-8]]
17   // CHECK: previously allocated by thread T0 here:
18   // CHECK-NEXT: {{#0 .* malloc }}
19   // CHECK: {{ #[1-3] .* main .*malloc_uaf.cpp}}:[[@LINE-12]]
20 }
21