Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 1 | // REQUIRES: asan-64-bits |
| 2 | // RUN: %clangxx_asan -O3 %s -o %t |
| 3 | // RUN: not %run %t 2>&1 | FileCheck %s |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 4 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s |
| 5 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | struct C { |
| 9 | int x; |
| 10 | ~C() { |
| 11 | fprintf(stderr, "ZZZZZZZZ\n"); |
| 12 | exit(1); |
| 13 | } |
| 14 | }; |
| 15 | |
| 16 | int main(int argc, char **argv) { |
| 17 | C *buffer = new C[argc]; |
| 18 | buffer[-2].x = 10; |
| 19 | // CHECK: AddressSanitizer: heap-buffer-overflow |
| 20 | // CHECK: in main {{.*}}new_array_cookie_test.cc:[[@LINE-2]] |
| 21 | // CHECK: is located 0 bytes inside of 12-byte region |
| 22 | // NO_COOKIE: ZZZZZZZZ |
| 23 | delete [] buffer; |
| 24 | } |