Home | History | Annotate | Download | only in TestCases
      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 // FIXME: Remove usage of backticks around basename below.
      8 // REQUIRES: shell
      9 
     10 // RUN: echo "interceptor_via_lib:"`basename %dynamiclib` > %t.supp
     11 // RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
     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
     43