| 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 | |
| 7 | int main() { |
| 8 | char str[] = "Hello" ; |
| 9 | if (5 != strlen(s: str)) |
| 10 | return 1; |
| 11 | |
| 12 | printf(format: "Initial test OK\n" ); |
| 13 | fflush(stream: 0); |
| 14 | // CHECK: Initial test OK |
| 15 | |
| 16 | str[5] = '!'; // Losing '\0' at the end. |
| 17 | int len = strlen(s: str); |
| 18 | // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] |
| 19 | // FIXME: Should be READ of size 1, see issue 155. |
| 20 | // CHECK: READ of size {{[0-9]+}} at [[ADDR]] thread T0 |
| 21 | // CHECK: strlen |
| 22 | // CHECK-NEXT: main {{.*}}intercept_strlen.cpp:[[@LINE-5]] |
| 23 | // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame |
| 24 | // CHECK-NEXT: main {{.*}}intercept_strlen.cpp |
| 25 | // CHECK: 'str'{{.*}} <== Memory access at offset {{.*}} overflows this variable |
| 26 | return len < 6; |
| 27 | } |
| 28 | |