blob: 5133b5c1653e2d800337360f38486d3fbc322ccc [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
Evgeniy Stepanov1bc72982013-02-05 14:32:03 +000025 // CHECK: {{WRITE of size 10 at 0x.* thread T0}}
Alexey Samsonov60164862012-08-15 08:29:17 +000026 // CHECK-Linux: {{ #0 0x.* in .*strncpy}}
Alexander Potapenko4b8e32d2012-11-09 11:55:33 +000027 // CHECK-Darwin: {{ #0 0x.* in _?wrap_strncpy}}
Alexey Samsonovf96bfd82012-12-28 08:38:09 +000028 // CHECK: {{ #1 0x.* in _?main .*strncpy-overflow.cc:}}[[@LINE-4]]
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 Samsonovf96bfd82012-12-28 08:38:09 +000033 // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:}}[[@LINE-10]]
Alexey Samsonov60164862012-08-15 08:29:17 +000034
Alexander Potapenkocae42d22013-01-22 09:14:54 +000035 // CHECK-Darwin: {{ #0 0x.* in _?wrap_malloc.*}}
36 // CHECK-Darwin: {{ #1 0x.* in _?main .*strncpy-overflow.cc:}}[[@LINE-13]]
Alexey Samsonov60164862012-08-15 08:29:17 +000037 return short_buffer[8];
38}