28 lines · cpp
1// RUN: %clang_cl_asan %Od %s %Fe%t2// RUN: not %run %t 2>&1 | FileCheck %s3 4#include <stdio.h>5#include <string.h>6 7int main() {8 char str[] = "Hello";9 if (5 != strlen(str))10 return 1;11 12 printf("Initial test OK\n");13 fflush(0);14// CHECK: Initial test OK15 16 str[5] = '!'; // Losing '\0' at the end.17 int len = strlen(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 T021// 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 frame24// CHECK-NEXT: main {{.*}}intercept_strlen.cpp25// CHECK: 'str'{{.*}} <== Memory access at offset {{.*}} overflows this variable26 return len < 6;27}28