blob: ce537a46d4bf9d41e001ace050be9bd84fe46fe9 [file] [log] [blame]
Alexey Samsonov0e056762012-08-15 08:54:14 +00001// RUN: %clangxx_asan -m64 -O2 %s -o %t
Alexey Samsonov60164862012-08-15 08:29:17 +00002// RUN: %t 2>&1 | %symbolizer | c++filt > %t.output
3// RUN: FileCheck %s < %t.output
4// RUN: FileCheck %s --check-prefix=CHECK-%os < %t.output
5
6#include <string.h>
7#include <stdlib.h>
8int main(int argc, char **argv) {
9 char *hello = (char*)malloc(6);
10 strcpy(hello, "hello");
11 char *short_buffer = (char*)malloc(9);
12 strncpy(short_buffer, hello, 10); // BOOM
13 // CHECK: {{WRITE of size 1 at 0x.* thread T0}}
14 // CHECK-Linux: {{ #0 0x.* in .*strncpy}}
15 // CHECK-Darwin: {{ #0 0x.* in wrap_strncpy}}
16 // CHECK: {{ #1 0x.* in main .*strncpy-overflow.cc:12}}
17 // CHECK: {{0x.* is located 0 bytes to the right of 9-byte region}}
18 // CHECK: {{allocated by thread T0 here:}}
19
20 // CHECK-Linux: {{ #0 0x.* in .*malloc}}
21 // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:11}}
22
23 // CHECK-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
24 // CHECK-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
25 // CHECK-Darwin: {{ #2 0x.* in malloc.*}}
26 // CHECK-Darwin: {{ #3 0x.* in main .*strncpy-overflow.cc:11}}
27 return short_buffer[8];
28}