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 // RUN: echo "interceptor_via_lib:"`basename %dynamiclib` > %t.supp
      8 // RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
      9 
     10 // XFAIL: android
     11 
     12 #include <stdio.h>
     13 #include <stdlib.h>
     14 #include <string.h>
     15 
     16 #if !defined(SHARED_LIB)
     17 
     18 void crash_function();
     19 
     20 int main(int argc, char *argv[]) {
     21   crash_function();
     22   return 0;
     23 }
     24 
     25 #else // SHARED_LIB
     26 
     27 void crash_function() {
     28   char *a = (char *)malloc(6);
     29   free(a);
     30   size_t len = strlen(a); // BOOM
     31   fprintf(stderr, "strlen ignored, %zu\n", len);
     32 }
     33 
     34 #endif // SHARED_LIB
     35 
     36 // CHECK-CRASH: AddressSanitizer: heap-use-after-free
     37 // CHECK-CRASH-NOT: strlen ignored
     38 // CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free
     39 // CHECK-IGNORE: strlen ignored
     40