comparison compiler-rt/test/hwasan/TestCases/tail-magic.c @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 1d019706d866
children 5f17cb93ff66
comparison
equal deleted inserted replaced
220:42394fc6a535 221:79ff65ed7e25
8 8
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <stdio.h> 10 #include <stdio.h>
11 #include <sanitizer/hwasan_interface.h> 11 #include <sanitizer/hwasan_interface.h>
12 12
13 #include "utils.h"
14
15 static volatile char *sink; 13 static volatile char *sink;
16 14
17 // Overwrite the tail in a non-hwasan function so that we don't detect the 15 // Overwrite the tail in a non-hwasan function so that we don't detect the
18 // stores as OOB. 16 // stores as OOB.
19 __attribute__((no_sanitize("hwaddress"))) void overwrite_tail() { 17 __attribute__((no_sanitize("hwaddress"))) void overwrite_tail() {
20 (*UNTAG(&sink))[20] = 0x42; 18 sink[20] = 0x42;
21 (*UNTAG(&sink))[24] = 0x66; 19 sink[24] = 0x66;
22 } 20 }
23 21
24 int main(int argc, char **argv) { 22 int main(int argc, char **argv) {
25 __hwasan_enable_allocator_tagging(); 23 __hwasan_enable_allocator_tagging();
26 24
27 char *p = (char*)malloc(20); 25 char *p = (char*)malloc(20);
28 sink = UNTAG(p); 26 sink = p;
29 overwrite_tail(); 27 overwrite_tail();
30 free(p); 28 free(p);
31 // CHECK: ERROR: HWAddressSanitizer: allocation-tail-overwritten; heap object [{{.*}}) of size 20 29 // CHECK: ERROR: HWAddressSanitizer: allocation-tail-overwritten; heap object [{{.*}}) of size 20
32 // CHECK: in main {{.*}}tail-magic.c:[[@LINE-2]] 30 // CHECK: in main {{.*}}tail-magic.c:[[@LINE-2]]
33 // CHECK: allocated here: 31 // CHECK: allocated here: