1// Check that without suppressions, we catch the issue.
2// RUN: %clangxx_asan -O0 %s -o %t -framework Foundation
3// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
4
5// Check that suppressing a function name works within a no-fork sandbox
6// RUN: echo "interceptor_via_fun:CFStringCreateWithBytes" > %t.supp
7// RUN: %env_asan_opts=suppressions='"%t.supp"' \
8// RUN: sandbox-exec -p '(version 1)(allow default)(deny process-fork)' \
9// RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
10
11// sandbox-exec isn't available on iOS
12// UNSUPPORTED: ios
13
14#include <CoreFoundation/CoreFoundation.h>
15
16int main() {
17 char *a = (char *)malloc(6);
18 strcpy(a, "hello");
19 CFStringRef str =
20 CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *)a, 10,
21 kCFStringEncodingUTF8, FALSE); // BOOM
22 fprintf(stderr, "Ignored.\n");
23 free(a);
24 CFRelease(str);
25}
26
27// CHECK-CRASH: AddressSanitizer: heap-buffer-overflow
28// CHECK-CRASH-NOT: Ignored.
29// CHECK-IGNORE-NOT: AddressSanitizer: heap-buffer-overflow
30// CHECK-IGNORE: Ignored.
31

source code of compiler-rt/test/asan/TestCases/Darwin/suppressions-sandbox.cpp