• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 // UNSUPPORTED: ios
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 struct C {
12   int x;
~CC13   ~C() {
14     fprintf(stderr, "ZZZZZZZZ\n");
15     exit(1);
16   }
17 };
18 
main(int argc,char ** argv)19 int main(int argc, char **argv) {
20   C *buffer = new C[argc];
21   buffer[-2].x = 10;
22 // CHECK: AddressSanitizer: heap-buffer-overflow
23 // CHECK: in main {{.*}}new_array_cookie_test.cpp:[[@LINE-2]]
24 // CHECK: is located 0 bytes inside of 12-byte region
25 // NO_COOKIE: ZZZZZZZZ
26   delete [] buffer;
27 }
28