1 | // Check that without suppressions, we catch the issue. |
---|---|
2 | // RUN: %clangxx_asan -O0 %s -o %t |
3 | // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s |
4 | |
5 | // RUN: echo "interceptor_via_fun:crash_function" > %t.supp |
6 | // RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s |
7 | // RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s |
8 | |
9 | // FIXME: Upload suppressions to device. |
10 | // XFAIL: android |
11 | // UNSUPPORTED: ios |
12 | |
13 | // FIXME: atos does not work for inlined functions, yet llvm-symbolizer |
14 | // does not always work with debug info on Darwin. Behavior is similar on MSVC x86 outside of /Od. |
15 | // UNSUPPORTED: darwin |
16 | // UNSUPPORTED: target={{.*windows-msvc.*}} && asan-32-bits |
17 | |
18 | #include <stdio.h> |
19 | #include <stdlib.h> |
20 | #include <string.h> |
21 | |
22 | void crash_function() { |
23 | char *a = (char *)malloc(size: 6); |
24 | free(ptr: a); |
25 | size_t len = strlen(s: a); // BOOM |
26 | fprintf(stderr, format: "strlen ignored, len = %zu\n", len); |
27 | } |
28 | |
29 | int main() { |
30 | crash_function(); |
31 | } |
32 | |
33 | // CHECK-CRASH: AddressSanitizer: heap-use-after-free |
34 | // CHECK-CRASH-NOT: strlen ignored |
35 | // CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free |
36 | // CHECK-IGNORE: strlen ignored |
37 |