54 lines · cpp
1// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=3162// UNSUPPORTED: ios, android3//4// The for loop in the backticks below requires bash.5// REQUIRES: shell6//7// RUN: %clangxx_asan %s -o %t8 9// Regular run.10// RUN: not %run %t 2> %t.out11// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out12 13// Good log_path.14// RUN: rm -f %t.log.*15// RUN: %env_asan_opts=log_path=%t.log not %run %t 2> %t.out16// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*17 18// Invalid log_path in existing directory.19// RUN: %env_asan_opts=log_path=/INVALID not %run %t 2> %t.out20// RUN: FileCheck %s --check-prefix=CHECK-INVALID < %t.out21 22// Directory of log_path can't be created.23// RUN: %env_asan_opts=log_path=/dev/null/INVALID not %run %t 2> %t.out24// RUN: FileCheck %s --check-prefix=CHECK-BAD-DIR < %t.out25 26// Too long log_path.27// RUN: %python -c "for i in range(0, 10000): print(i, end='')" > %t.long_log_path28// RUN: %env_asan_opts=log_path=%{readfile:%t.long_log_path} \29// RUN: not %run %t 2> %t.out30// RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out31 32// Run w/o errors should not produce any log.33// RUN: rm -f %t.log.*34// RUN: %env_asan_opts=log_path=%t.log %run %t ARG ARG ARG35// RUN: not cat %t.log.*36 37// FIXME: log_path is not supported on Windows yet.38// XFAIL: target={{.*windows-msvc.*}}39 40#include <stdlib.h>41#include <string.h>42int main(int argc, char **argv) {43 if (argc > 2) return 0;44 char *x = (char*)malloc(10);45 memset(x, 0, 10);46 int res = x[argc * 10]; // BOOOM47 free(x);48 return res;49}50// CHECK-ERROR: ERROR: AddressSanitizer51// CHECK-INVALID: ERROR: Can't open file: /INVALID52// CHECK-BAD-DIR: ERROR: Can't create directory: /dev/null53// CHECK-LONG: ERROR: Path is too long: 0123454