31 lines · cpp
1// REQUIRES: asan-64-bits2// RUN: %clangxx_asan -O3 %s -o %t3// RUN: not %run %t 2>&1 | FileCheck %s4// RUN: %env_asan_opts=poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s5// RUN: %env_asan_opts=poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE6 7// UNSUPPORTED: ios8 9// Poisoning C++ array redzones is not implemented on arm10// XFAIL: target=arm{{.*}}11 12#include <stdio.h>13#include <stdlib.h>14struct C {15 int x;16 ~C() {17 fprintf(stderr, "ZZZZZZZZ\n");18 exit(1);19 }20};21 22int main(int argc, char **argv) {23 C *buffer = new C[argc];24 buffer[-2].x = 10;25// CHECK: AddressSanitizer: heap-buffer-overflow26// CHECK: in main {{.*}}new_array_cookie_test.cpp:[[@LINE-2]]27// CHECK: is located 0 bytes inside of 12-byte region28// NO_COOKIE: ZZZZZZZZ29 delete [] buffer;30}31