1 | // RUN: %clangxx_asan -O0 -DSHARED_LIB %s %fPIC -shared -o %dynamiclib %ld_flags_rpath_so |
2 | // RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe |
3 | |
4 | // Check that without suppressions, we catch the issue. |
5 | // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s |
6 | |
7 | // REQUIRES: shell |
8 | |
9 | // RUN: echo "interceptor_via_lib:"%xdynamiclib_filename > %t.supp |
10 | // RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s |
11 | |
12 | // XFAIL: android |
13 | |
14 | #include <stdio.h> |
15 | #include <stdlib.h> |
16 | #include <string.h> |
17 | |
18 | #if !defined(SHARED_LIB) |
19 | |
20 | void crash_function(); |
21 | |
22 | int main(int argc, char *argv[]) { |
23 | crash_function(); |
24 | return 0; |
25 | } |
26 | |
27 | #else // SHARED_LIB |
28 | |
29 | void crash_function() { |
30 | char *a = (char *)malloc(6); |
31 | free(a); |
32 | size_t len = strlen(a); // BOOM |
33 | fprintf(stderr, "strlen ignored, %zu\n" , len); |
34 | } |
35 | |
36 | #endif // SHARED_LIB |
37 | |
38 | // CHECK-CRASH: AddressSanitizer: heap-use-after-free |
39 | // CHECK-CRASH-NOT: strlen ignored |
40 | // CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free |
41 | // CHECK-IGNORE: strlen ignored |
42 | |