1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2 // XFAIL: android
3 //
4 // The for loop in the backticks below requires bash.
5 // REQUIRES: shell
6 //
7 // RUN: %clangxx_asan  %s -o %t
8 
9 // Regular run.
10 // RUN: not %run %t 2> %t.out
11 // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out
12 
13 // Good log_path.
14 // RUN: rm -f %t.log.*
15 // RUN: %env_asan_opts=log_path=%t.log not %run %t 2> %t.out
16 // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*
17 
18 // Invalid log_path.
19 // RUN: %env_asan_opts=log_path=/dev/null/INVALID not %run %t 2> %t.out
20 // RUN: FileCheck %s --check-prefix=CHECK-INVALID < %t.out
21 
22 // Too long log_path.
23 // RUN: %env_asan_opts=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
24 // RUN:   not %run %t 2> %t.out
25 // RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out
26 
27 // Run w/o errors should not produce any log.
28 // RUN: rm -f %t.log.*
29 // RUN: %env_asan_opts=log_path=%t.log  %run %t ARG ARG ARG
30 // RUN: not cat %t.log.*
31 
32 // FIXME: log_path is not supported on Windows yet.
33 // XFAIL: win32
34 
35 #include <stdlib.h>
36 #include <string.h>
main(int argc,char ** argv)37 int main(int argc, char **argv) {
38   if (argc > 2) return 0;
39   char *x = (char*)malloc(10);
40   memset(x, 0, 10);
41   int res = x[argc * 10];  // BOOOM
42   free(x);
43   return res;
44 }
45 // CHECK-ERROR: ERROR: AddressSanitizer
46 // CHECK-INVALID: ERROR: Can't open file: /dev/null/INVALID
47 // CHECK-LONG: ERROR: Path is too long: 01234
48