1 // RUN: %clangxx_asan -m64 -O0 %s -o %t && %t 2>&1 | %symbolize > %t.out 2 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 3 // RUN: %clangxx_asan -m64 -O1 %s -o %t && %t 2>&1 | %symbolize > %t.out 4 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 5 // RUN: %clangxx_asan -m64 -O2 %s -o %t && %t 2>&1 | %symbolize > %t.out 6 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 7 // RUN: %clangxx_asan -m64 -O3 %s -o %t && %t 2>&1 | %symbolize > %t.out 8 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 9 // RUN: %clangxx_asan -m32 -O0 %s -o %t && %t 2>&1 | %symbolize > %t.out 10 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 11 // RUN: %clangxx_asan -m32 -O1 %s -o %t && %t 2>&1 | %symbolize > %t.out 12 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 13 // RUN: %clangxx_asan -m32 -O2 %s -o %t && %t 2>&1 | %symbolize > %t.out 14 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 15 // RUN: %clangxx_asan -m32 -O3 %s -o %t && %t 2>&1 | %symbolize > %t.out 16 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out 17 18 #include <string.h> 19 #include <stdlib.h> 20 int main(int argc, char **argv) { 21 char *hello = (char*)malloc(6); 22 strcpy(hello, "hello"); 23 char *short_buffer = (char*)malloc(9); 24 strncpy(short_buffer, hello, 10); // BOOM 25 // CHECK: {{WRITE of size 1 at 0x.* thread T0}} 26 // CHECK-Linux: {{ #0 0x.* in .*strncpy}} 27 // CHECK-Darwin: {{ #0 0x.* in wrap_strncpy}} 28 // CHECK: {{ #1 0x.* in main .*strncpy-overflow.cc:24}} 29 // CHECK: {{0x.* is located 0 bytes to the right of 9-byte region}} 30 // CHECK: {{allocated by thread T0 here:}} 31 32 // CHECK-Linux: {{ #0 0x.* in .*malloc}} 33 // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:23}} 34 35 // CHECK-Darwin: {{ #0 0x.* in .*mz_malloc.*}} 36 // CHECK-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}} 37 // CHECK-Darwin: {{ #2 0x.* in malloc.*}} 38 // CHECK-Darwin: {{ #3 0x.* in main .*strncpy-overflow.cc:23}} 39 return short_buffer[8]; 40 } 41