Alexey Samsonov | 13f89cd | 2013-06-28 15:52:44 +0000 | [diff] [blame^] | 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>%t.out |
Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 2 | // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out |
Alexey Samsonov | 13f89cd | 2013-06-28 15:52:44 +0000 | [diff] [blame^] | 3 | // RUN: %clangxx_asan -O1 %s -o %t && not %t 2>%t.out |
Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 4 | // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out |
Alexey Samsonov | 13f89cd | 2013-06-28 15:52:44 +0000 | [diff] [blame^] | 5 | // RUN: %clangxx_asan -O2 %s -o %t && not %t 2>%t.out |
Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 6 | // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out |
Alexey Samsonov | 13f89cd | 2013-06-28 15:52:44 +0000 | [diff] [blame^] | 7 | // RUN: %clangxx_asan -O3 %s -o %t && not %t 2>%t.out |
Alexey Samsonov | 9fe914b | 2012-08-15 11:26:57 +0000 | [diff] [blame] | 8 | // 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] | 9 | |
| 10 | #include <string.h> |
| 11 | #include <stdlib.h> |
| 12 | int 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 Stepanov | 1bc7298 | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 17 | // CHECK: {{WRITE of size 10 at 0x.* thread T0}} |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 18 | // CHECK-Linux: {{ #0 0x.* in .*strncpy}} |
Alexander Potapenko | 4b8e32d | 2012-11-09 11:55:33 +0000 | [diff] [blame] | 19 | // CHECK-Darwin: {{ #0 0x.* in _?wrap_strncpy}} |
Alexey Samsonov | f96bfd8 | 2012-12-28 08:38:09 +0000 | [diff] [blame] | 20 | // CHECK: {{ #1 0x.* in _?main .*strncpy-overflow.cc:}}[[@LINE-4]] |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 21 | // 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 Samsonov | f96bfd8 | 2012-12-28 08:38:09 +0000 | [diff] [blame] | 25 | // CHECK-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:}}[[@LINE-10]] |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 26 | |
Alexander Potapenko | cae42d2 | 2013-01-22 09:14:54 +0000 | [diff] [blame] | 27 | // CHECK-Darwin: {{ #0 0x.* in _?wrap_malloc.*}} |
| 28 | // CHECK-Darwin: {{ #1 0x.* in _?main .*strncpy-overflow.cc:}}[[@LINE-13]] |
Alexey Samsonov | 6016486 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 29 | return short_buffer[8]; |
| 30 | } |