Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 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 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 3 | |
| 4 | // Check that without suppressions, we catch the issue. |
| 5 | // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s |
| 6 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 7 | // FIXME: Remove usage of backticks around basename below. |
| 8 | // REQUIRES: shell |
| 9 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 10 | // RUN: echo "interceptor_via_lib:"`basename %dynamiclib` > %t.supp |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 11 | // RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 12 | |
| 13 | // XFAIL: android |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <string.h> |
| 18 | |
| 19 | #if !defined(SHARED_LIB) |
| 20 | |
| 21 | void crash_function(); |
| 22 | |
| 23 | int main(int argc, char *argv[]) { |
| 24 | crash_function(); |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | #else // SHARED_LIB |
| 29 | |
| 30 | void crash_function() { |
| 31 | char *a = (char *)malloc(6); |
| 32 | free(a); |
| 33 | size_t len = strlen(a); // BOOM |
| 34 | fprintf(stderr, "strlen ignored, %zu\n", len); |
| 35 | } |
| 36 | |
| 37 | #endif // SHARED_LIB |
| 38 | |
| 39 | // CHECK-CRASH: AddressSanitizer: heap-use-after-free |
| 40 | // CHECK-CRASH-NOT: strlen ignored |
| 41 | // CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free |
| 42 | // CHECK-IGNORE: strlen ignored |