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 | FileCheck %s 5 // RUN: not %run %t 2>&1 | FileCheck %s 6 7 // REQUIRES: stable-runtime 8 9 #include <stdlib.h> 10 #include <stdio.h> 11 #include <sanitizer/hwasan_interface.h> 12 13 #include "utils.h" 14 15 static volatile char *sink; 16 17 // Overwrite the tail in a non-hwasan function so that we don't detect the 18 // stores as OOB. overwrite_tail()19__attribute__((no_sanitize("hwaddress"))) void overwrite_tail() { 20 (*UNTAG(&sink))[20] = 0x42; 21 (*UNTAG(&sink))[24] = 0x66; 22 } 23 main(int argc,char ** argv)24int main(int argc, char **argv) { 25 __hwasan_enable_allocator_tagging(); 26 27 char *p = (char*)malloc(20); 28 sink = UNTAG(p); 29 overwrite_tail(); 30 free(p); 31 // CHECK: ERROR: HWAddressSanitizer: allocation-tail-overwritten; heap object [{{.*}}) of size 20 32 // CHECK: in main {{.*}}tail-magic.c:[[@LINE-2]] 33 // CHECK: allocated here: 34 // CHECK: in main {{.*}}tail-magic.c:[[@LINE-7]] 35 // CHECK: Tail contains: .. .. .. .. 42 {{.. .. ..}} 66 36 } 37