aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Darwin/suppressions-sandbox.cc
blob: 47d80f80db2bc298091c8bdfb3b4dbdef33e4f93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Check that without suppressions, we catch the issue.
// RUN: %clangxx_asan -O0 %s -o %t -framework Foundation
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s

// Check that suppressing a function name works within a no-fork sandbox
// RUN: echo "interceptor_via_fun:CFStringCreateWithBytes" > %t.supp
// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:suppressions=%t.supp \
// RUN:   sandbox-exec -p '(version 1)(allow default)(deny process-fork)' \
// RUN:   %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s

#include <CoreFoundation/CoreFoundation.h>

int main() {
  char *a = (char *)malloc(6);
  strcpy(a, "hello");
  CFStringRef str =
      CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *)a, 10,
                              kCFStringEncodingUTF8, FALSE);  // BOOM
  fprintf(stderr, "Ignored.\n");
  free(a);
}

// CHECK-CRASH: AddressSanitizer: heap-buffer-overflow
// CHECK-CRASH-NOT: Ignored.
// CHECK-IGNORE-NOT: AddressSanitizer: heap-buffer-overflow
// CHECK-IGNORE: Ignored.