• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // RUN: echo "interceptor_via_fun:crash_function" > %t.supp
6 // RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
7 // RUN: %clangxx_asan -O3 %s -o %t && ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
8 
9 // XFAIL: android
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 
crash_function()15 void crash_function() {
16   char *a = (char *)malloc(6);
17   free(a);
18   size_t len = strlen(a); // BOOM
19   fprintf(stderr, "strlen ignored, len = %zu\n", len);
20 }
21 
main()22 int main() {
23   crash_function();
24 }
25 
26 // CHECK-CRASH: AddressSanitizer: heap-use-after-free
27 // CHECK-CRASH-NOT: strlen ignored
28 // CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free
29 // CHECK-IGNORE: strlen ignored
30