Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 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 |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 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}} |
Alexander Potapenko | 4b8e32d | 2012-11-09 11:55:33 +0000 | [diff] [blame] | 27 | // CHECK-Darwin: {{ #0 0x.* in _?wrap_strncpy}} |
Alexey Samsonov | 480477c | 2012-10-08 13:11:18 +0000 | [diff] [blame] | 28 | // CHECK: {{ #1 0x.* in _?main .*strncpy-overflow.cc:24}} |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 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}} |
Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 33 | // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:23}} |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 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.*}} |
Alexey Samsonov | 480477c | 2012-10-08 13:11:18 +0000 | [diff] [blame] | 38 | // CHECK-Darwin: {{ #3 0x.* in _?main .*strncpy-overflow.cc:23}} |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 39 | return short_buffer[8]; |
| 40 | } |