35 lines · cpp
1// In a non-forking sandbox, we can't spawn an external symbolizer, but dladdr()2// should still work and provide function names. No line numbers though.3// Second, `atos` symbolizer can't inspect a process that has an inaccessible4// task port, in which case we should again fallback to dladdr gracefully.5 6// RUN: %clangxx_asan -O0 %s -o %t 7// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s8// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-exec (literal "/usr/bin/atos"))' %t 2>&1 | FileCheck %s9// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s10// RUN: env ASAN_SYMBOLIZER_PATH="" not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s11// RUN: %clangxx_asan -O3 %s -o %t 12// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s13// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-exec (literal "/usr/bin/atos"))' %t 2>&1 | FileCheck %s14// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s15// RUN: env ASAN_SYMBOLIZER_PATH="" not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s16 17// sandbox-exec isn't available on iOS18// UNSUPPORTED: ios19 20#include <stdlib.h>21int main() {22 char *x = (char*)malloc(10 * sizeof(char));23 free(x);24 return x[5];25 // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}26 // CHECK: {{READ of size 1 at 0x.* thread T0}}27 // CHECK: {{ #0 0x.* in main}}28 // CHECK: {{freed by thread T0 here:}}29 // CHECK: {{ #0 0x.* in free}}30 // CHECK: {{ #1 0x.* in main}}31 // CHECK: {{previously allocated by thread T0 here:}}32 // CHECK: {{ #0 0x.* in malloc}}33 // CHECK: {{ #1 0x.* in main}}34}35