Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 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 | // If the executable is started from a different location, we should still |
| 6 | // find the suppression file located relative to the location of the executable. |
| 7 | // RUN: rm -rf %T/suppressions-exec-relative-location |
| 8 | // RUN: mkdir -p %T/suppressions-exec-relative-location |
| 9 | // RUN: %clangxx_asan -O0 %s -o %T/suppressions-exec-relative-location/exec |
| 10 | // RUN: echo "interceptor_via_fun:crash_function" > \ |
| 11 | // RUN: %T/suppressions-exec-relative-location/supp.txt |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 12 | // RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions=supp.txt" \ |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 13 | // RUN: %run %T/suppressions-exec-relative-location/exec 2>&1 | \ |
| 14 | // RUN: FileCheck --check-prefix=CHECK-IGNORE %s |
| 15 | // RUN: rm -rf %T/suppressions-exec-relative-location |
| 16 | |
| 17 | // If the wrong absolute path is given, we don't try to construct |
| 18 | // a relative path with it. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 19 | // RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='/absolute/path'" not %run %t 2>&1 | \ |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 20 | // RUN: FileCheck --check-prefix=CHECK-WRONG-FILE-NAME %s |
| 21 | |
| 22 | // Test that we reject directory as filename. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 23 | // RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='folder/only/'" not %run %t 2>&1 | \ |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 24 | // RUN: FileCheck --check-prefix=CHECK-WRONG-FILE-NAME %s |
| 25 | |
| 26 | // XFAIL: android |
| 27 | // XFAIL: win32 |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | |
| 33 | void crash_function() { |
| 34 | char *a = (char *)malloc(6); |
| 35 | free(a); |
| 36 | size_t len = strlen(a); // BOOM |
| 37 | fprintf(stderr, "strlen ignored, len = %zu\n", len); |
| 38 | } |
| 39 | |
| 40 | int main() { |
| 41 | crash_function(); |
| 42 | } |
| 43 | |
| 44 | // CHECK-CRASH: AddressSanitizer: heap-use-after-free |
| 45 | // CHECK-IGNORE-NOT: AddressSanitizer: heap-buffer-overflow |
| 46 | // CHECK-IGNORE: ignored |
| 47 | // CHECK-WRONG-FILE-NAME: failed to read suppressions file |