brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 7b61df0 Raw
32 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t 2>&12// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=MALLOC-CTX3 4// Also works if no malloc context is available.5// RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s6// RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s7 8// RUN: %clangxx_asan -O0 -fsanitize-recover=address %s -o %t 2>&19// RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER10// REQUIRES: stable-runtime11 12#include <stdlib.h>13#include <string.h>14int main(int argc, char **argv) {15  char *x = (char*)malloc(10 * sizeof(char));16  memset(x, 0, 10);17  int res = x[argc];18  free(x);19  free(x + argc - 1);  // BOOM20  // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T021  // CHECK: #0 0x{{.*}} in {{.*}}free22  // CHECK: #{{[1-3]}} 0x{{.*}} in main {{.*}}double-free.cpp:[[@LINE-3]]23  // CHECK: freed by thread T0 here:24  // MALLOC-CTX: #0 0x{{.*}} in {{.*}}free25  // MALLOC-CTX: #{{[1-3]}} 0x{{.*}} in main {{.*}}double-free.cpp:[[@LINE-7]]26  // CHECK: allocated by thread T0 here:27  // MALLOC-CTX: double-free.cpp:[[@LINE-12]]28  // CHECK-RECOVER: AddressSanitizer: attempting double-free{{.*}}in thread T029  // CHECK-RECOVER-NOT: AddressSanitizer CHECK failed:30  return res;31}32