diff options
Diffstat (limited to 'compiler-rt/test/asan')
4 files changed, 120 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc b/compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc new file mode 100644 index 00000000000..9a8f56d5dc5 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc @@ -0,0 +1,34 @@ +// 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 the interceptor by name works. +// RUN: echo "interceptor_name:memmove" > %t.supp +// RUN: ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s + +// Check that suppressing by interceptor name works even without the symbolizer +// RUN: ASAN_OPTIONS=suppressions=%t.supp:symbolize=false %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s + +// Check that suppressing all reports from a library works. +// RUN: echo "interceptor_via_lib:CoreFoundation" > %t.supp +// RUN: ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s + +// Check that suppressing library works even without the symbolizer. +// RUN: ASAN_OPTIONS=suppressions=%t.supp:symbolize=false %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. diff --git a/compiler-rt/test/asan/TestCases/suppressions-function.cc b/compiler-rt/test/asan/TestCases/suppressions-function.cc new file mode 100644 index 00000000000..c18659e9f7b --- /dev/null +++ b/compiler-rt/test/asan/TestCases/suppressions-function.cc @@ -0,0 +1,27 @@ +// Check that without suppressions, we catch the issue. +// RUN: %clangxx_asan -O0 %s -o %t +// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s + +// RUN: echo "interceptor_via_fun:crash_function" > %t.supp +// RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s +// RUN: %clangxx_asan -O3 %s -o %t && ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void crash_function() { + char *a = (char *)malloc(6); + free(a); + size_t len = strlen(a); // BOOM + fprintf(stderr, "strlen ignored, len = %zu\n", len); +} + +int main() { + crash_function(); +} + +// CHECK-CRASH: AddressSanitizer: heap-use-after-free +// CHECK-CRASH-NOT: strlen ignored +// CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free +// CHECK-IGNORE: strlen ignored diff --git a/compiler-rt/test/asan/TestCases/suppressions-interceptor.cc b/compiler-rt/test/asan/TestCases/suppressions-interceptor.cc new file mode 100644 index 00000000000..a86d7c5cfac --- /dev/null +++ b/compiler-rt/test/asan/TestCases/suppressions-interceptor.cc @@ -0,0 +1,22 @@ +// Check that without suppressions, we catch the issue. +// RUN: %clangxx_asan -O0 %s -o %t +// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s + +// RUN: echo "interceptor_name:strlen" > %t.supp +// RUN: ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main() { + char *a = (char *)malloc(6); + free(a); + size_t len = strlen(a); // BOOM + fprintf(stderr, "strlen ignored, len = %zu\n", len); +} + +// CHECK-CRASH: AddressSanitizer: heap-use-after-free +// CHECK-CRASH-NOT: strlen ignored +// CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free +// CHECK-IGNORE: strlen ignored diff --git a/compiler-rt/test/asan/TestCases/suppressions-library.cc b/compiler-rt/test/asan/TestCases/suppressions-library.cc new file mode 100644 index 00000000000..cb4db013c1d --- /dev/null +++ b/compiler-rt/test/asan/TestCases/suppressions-library.cc @@ -0,0 +1,37 @@ +// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so +// RUN: %clangxx_asan -O0 %s %t-so.so -o %t + +// Check that without suppressions, we catch the issue. +// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s + +// RUN: echo "interceptor_via_lib:%t-so.so" > %t.supp +// RUN: ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(SHARED_LIB) + +void crash_function(); + +int main(int argc, char *argv[]) { + crash_function(); + return 0; +} + +#else // SHARED_LIB + +void crash_function() { + char *a = (char *)malloc(6); + free(a); + size_t len = strlen(a); // BOOM + fprintf(stderr, "strlen ignored, %zu\n", len); +} + +#endif // SHARED_LIB + +// CHECK-CRASH: AddressSanitizer: heap-use-after-free +// CHECK-CRASH-NOT: strlen ignored +// CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free +// CHECK-IGNORE: strlen ignored |

