xref: /llvm-project/compiler-rt/test/hwasan/TestCases/realloc-after-free.c (revision fdac98a7f3bbe0cb553df60df8cca2e8f407fa51)
1 // RUN: %clang_hwasan %s -o %t
2 // RUN: not %run %t 50 2>&1 | FileCheck %s
3 // RUN: not %run %t 40 2>&1 | FileCheck %s
4 // RUN: not %run %t 30 2>&1 | FileCheck %s
5 
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <sanitizer/hwasan_interface.h>
9 
main(int argc,char ** argv)10 int main(int argc, char **argv) {
11   __hwasan_enable_allocator_tagging();
12   if (argc != 2) return 0;
13   int realloc_size = atoi(argv[1]);
14   char * volatile x = (char*)malloc(40);
15   free(x);
16   x = realloc(x, realloc_size);
17   // CHECK: ERROR: HWAddressSanitizer: invalid-free on address
18   // CHECK: tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem)
19   // CHECK: freed by thread {{.*}} here:
20   // CHECK: previously allocated by thread {{.*}} here:
21   // CHECK: Memory tags around the buggy address (one tag corresponds to 16 bytes):
22   // CHECK: =>{{.*}}[[MEM_TAG]]
23   fprintf(stderr, "DONE\n");
24   __hwasan_disable_allocator_tagging();
25 // CHECK-NOT: DONE
26 }
27