1 // Tests free_checks_tail_magic=1.
2 // RUN: %clang_hwasan %s -o %t
3 // RUN: %env_hwasan_opts=free_checks_tail_magic=0 %run %t
4 // RUN: %env_hwasan_opts=free_checks_tail_magic=1 not %run %t 2>&1 | \
5 // RUN: FileCheck --check-prefixes=CHECK,CHECK-NONLASTGRANULE --strict-whitespace %s
6 // RUN: not %run %t 2>&1 | \
7 // RUN: FileCheck --check-prefixes=CHECK,CHECK-NONLASTGRANULE --strict-whitespace %s
8 // RUN: %clang_hwasan -DLAST_GRANULE %s -o %t
9 // RUN: not %run %t 2>&1 | \
10 // RUN: FileCheck --check-prefixes=CHECK,CHECK-LASTGRANULE --strict-whitespace %s
14 #include <sanitizer/hwasan_interface.h>
16 static volatile char *sink
;
18 // Overwrite the tail in a non-hwasan function so that we don't detect the
20 __attribute__((no_sanitize("hwaddress"))) void overwrite_tail() {
26 #endif // LAST_GRANULE
29 int main(int argc
, char **argv
) {
30 __hwasan_enable_allocator_tagging();
32 char *p
= (char*)malloc(20);
33 __hwasan_print_shadow(p
, 1);
37 // CHECK: HWASan shadow map for {{.*}} (pointer tag [[TAG:[a-f0-9]+]])
38 // CHECK: ERROR: HWAddressSanitizer: allocation-tail-overwritten; heap object [{{.*}}) of size 20
39 // CHECK: Stack of invalid access unknown. Issue detected at deallocation time.
40 // CHECK: deallocated here:
41 // CHECK: in main {{.*}}tail-magic.c:[[@LINE-5]]
42 // CHECK: allocated here:
43 // CHECK: in main {{.*}}tail-magic.c:[[@LINE-11]]
44 // CHECK-NONLASTGRANULE: Tail contains: .. .. .. .. 42 {{(([a-f0-9]{2} ){3})}}66
45 // CHECK-LASTGRANULE: Tail contains: .. .. .. .. {{(([a-f0-9]{2} ?)+)}}71{{ *$}}
46 // CHECK-NEXT: Expected: {{ +}} .. .. .. .. {{([a-f0-9]{2} )+0?}}[[TAG]]{{ *$}}
47 // CHECK-NONLASTGRANULE-NEXT: {{ +}}^^{{ +}}^^{{ *$}}
48 // CHECK-LASTGRANULE-NEXT: {{ +}}^^{{ *$}}