1 // REQUIRES: asan-64-bits 2 // RUN: %clangxx_asan -O3 %s -o %t 3 // RUN: not %run %t 2>&1 | FileCheck %s 4 // RUN: %env_asan_opts=poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s 5 // RUN: %env_asan_opts=poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE 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 } 25