1 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
2 // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
3 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
4 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
5
6 // REQUIRES: compiler-rt-optimized
7 // XFAIL: arm-linux-gnueabi
8 // XFAIL: armv7l-unknown-linux-gnueabihf
9
10 #include <string.h>
11 #include <stdlib.h>
main(int argc,char ** argv)12 int main(int argc, char **argv) {
13 char *hello = (char*)malloc(6);
14 strcpy(hello, "hello");
15 char *short_buffer = (char*)malloc(9);
16 strncpy(short_buffer, hello, 10); // BOOM
17 // CHECK: {{WRITE of size 10 at 0x.* thread T0}}
18 // CHECK-Linux: {{ #0 0x.* in .*strncpy}}
19 // CHECK-Darwin: {{ #0 0x.* in wrap_strncpy}}
20 // CHECK: {{ #1 0x.* in main .*strncpy-overflow.cc:}}[[@LINE-4]]
21 // CHECK: {{0x.* is located 0 bytes to the right of 9-byte region}}
22 // CHECK: {{allocated by thread T0 here:}}
23
24 // CHECK-Linux: {{ #0 0x.* in .*malloc}}
25 // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:}}[[@LINE-10]]
26
27 // CHECK-Darwin: {{ #0 0x.* in wrap_malloc.*}}
28 // CHECK-Darwin: {{ #1 0x.* in main .*strncpy-overflow.cc:}}[[@LINE-13]]
29 return short_buffer[8];
30 }
31