blob: 54eabe13234ce8bd308deff0aacf32e9597cb3c4 [file] [log] [blame]
Alexey Samsonov13f89cd2013-06-28 15:52:44 +00001// RUN: %clangxx_asan -O0 %s -o %t && not %t 2>%t.out
Alexey Samsonov9fe914b2012-08-15 11:26:57 +00002// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
Alexey Samsonov13f89cd2013-06-28 15:52:44 +00003// RUN: %clangxx_asan -O1 %s -o %t && not %t 2>%t.out
Alexey Samsonov9fe914b2012-08-15 11:26:57 +00004// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
Alexey Samsonov13f89cd2013-06-28 15:52:44 +00005// RUN: %clangxx_asan -O2 %s -o %t && not %t 2>%t.out
Alexey Samsonov9fe914b2012-08-15 11:26:57 +00006// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
Alexey Samsonov13f89cd2013-06-28 15:52:44 +00007// RUN: %clangxx_asan -O3 %s -o %t && not %t 2>%t.out
Alexey Samsonov9fe914b2012-08-15 11:26:57 +00008// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
Alexey Samsonov60164862012-08-15 08:29:17 +00009
10#include <string.h>
11#include <stdlib.h>
12int 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
Evgeniy Stepanov1bc72982013-02-05 14:32:03 +000017 // CHECK: {{WRITE of size 10 at 0x.* thread T0}}
Alexey Samsonov60164862012-08-15 08:29:17 +000018 // CHECK-Linux: {{ #0 0x.* in .*strncpy}}
Alexander Potapenko4b8e32d2012-11-09 11:55:33 +000019 // CHECK-Darwin: {{ #0 0x.* in _?wrap_strncpy}}
Alexey Samsonovf96bfd82012-12-28 08:38:09 +000020 // CHECK: {{ #1 0x.* in _?main .*strncpy-overflow.cc:}}[[@LINE-4]]
Alexey Samsonov60164862012-08-15 08:29:17 +000021 // 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}}
Alexey Samsonovf96bfd82012-12-28 08:38:09 +000025 // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:}}[[@LINE-10]]
Alexey Samsonov60164862012-08-15 08:29:17 +000026
Alexander Potapenkocae42d22013-01-22 09:14:54 +000027 // CHECK-Darwin: {{ #0 0x.* in _?wrap_malloc.*}}
28 // CHECK-Darwin: {{ #1 0x.* in _?main .*strncpy-overflow.cc:}}[[@LINE-13]]
Alexey Samsonov60164862012-08-15 08:29:17 +000029 return short_buffer[8];
30}