1 | // RUN: %clang_cl_asan %Od %s %Fe%t |
2 | // RUN: not %run %t 2>&1 | FileCheck %s |
3 | |
4 | #include <stdio.h> |
5 | #include <string.h> |
6 | #include <malloc.h> |
7 | |
8 | int main() { |
9 | char *ptr = _strdup(s: "Hello" ); |
10 | int subscript = 1; |
11 | ptr[subscript] = '3'; |
12 | printf(format: "%s\n" , ptr); |
13 | fflush(stream: 0); |
14 | // CHECK: H3llo |
15 | |
16 | subscript = -1; |
17 | ptr[subscript] = 42; |
18 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] |
19 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 |
20 | // CHECK: {{#0 .* main .*}}intercept_strdup.cpp:[[@LINE-3]] |
21 | // CHECK: [[ADDR]] is located 1 bytes before 6-byte region |
22 | // CHECK: allocated by thread T0 here: |
23 | // |
24 | // The first frame is our wrapper normally but will be malloc in the dynamic |
25 | // config. |
26 | // CHECK: #0 {{.*}} in {{malloc|_strdup}} |
27 | // |
28 | // The local call to _strdup above may be the second or third frame depending |
29 | // on whether we're using the dynamic config. |
30 | // CHECK: #{{[12]}} {{.*}} in main {{.*}}intercept_strdup.cpp:[[@LINE-21]] |
31 | free(ptr: ptr); |
32 | } |
33 | |