blob: 9381f13788c5307a45e0da7a658aa8b5dca8e6ff [file] [log] [blame]
Alexey Samsonov9fe914b2012-08-15 11:26:57 +00001// 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
Alexey Samsonov60164862012-08-15 08:29:17 +000017
18#include <string.h>
19#include <stdlib.h>
20int 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}}
Alexander Potapenko4b8e32d2012-11-09 11:55:33 +000027 // CHECK-Darwin: {{ #0 0x.* in _?wrap_strncpy}}
Alexey Samsonov480477c2012-10-08 13:11:18 +000028 // CHECK: {{ #1 0x.* in _?main .*strncpy-overflow.cc:24}}
Alexey Samsonov60164862012-08-15 08:29:17 +000029 // 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}}
Alexey Samsonov9fe914b2012-08-15 11:26:57 +000033 // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:23}}
Alexey Samsonov60164862012-08-15 08:29:17 +000034
35 // CHECK-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
36 // CHECK-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
37 // CHECK-Darwin: {{ #2 0x.* in malloc.*}}
Alexey Samsonov480477c2012-10-08 13:11:18 +000038 // CHECK-Darwin: {{ #3 0x.* in _?main .*strncpy-overflow.cc:23}}
Alexey Samsonov60164862012-08-15 08:29:17 +000039 return short_buffer[8];
40}