comparison compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.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
13 13
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <stdio.h> 15 #include <stdio.h>
16 #include <sanitizer/hwasan_interface.h> 16 #include <sanitizer/hwasan_interface.h>
17 17
18 #include "utils.h"
19
20 static volatile char sink; 18 static volatile char sink;
21 19
22 int main(int argc, char **argv) { 20 int main(int argc, char **argv) {
23 __hwasan_enable_allocator_tagging(); 21 __hwasan_enable_allocator_tagging();
24 int offset = argc < 2 ? 40 : atoi(argv[1]); 22 int offset = argc < 2 ? 40 : atoi(argv[1]);
25 int size = argc < 3 ? 30 : atoi(argv[2]); 23 int size = argc < 3 ? 30 : atoi(argv[2]);
26 char * volatile x = (char*)malloc(size); 24 char * volatile x = (char*)malloc(size);
27 untag_fprintf(stderr, "base: %p access: %p\n", x, &x[offset]); 25 fprintf(stderr, "base: %p access: %p\n", x, &x[offset]);
28 sink = x[offset]; 26 sink = x[offset];
27
28 #if defined(__x86_64__)
29 // Aliasing mode doesn't support the secondary allocator, so we fake a HWASan
30 // report instead of disabling the entire test.
31 if (size == 1000000) {
32 fprintf(stderr, "is a large allocated heap chunk; size: 1003520 offset: %d\n",
33 offset);
34 fprintf(stderr, "is located %s of 1000000-byte region\n",
35 offset == -30 ? "30 bytes to the left" : "0 bytes to the right");
36 return -1;
37 }
38 #endif
29 39
30 // CHECK40: allocated heap chunk; size: 32 offset: 8 40 // CHECK40: allocated heap chunk; size: 32 offset: 8
31 // CHECK40: is located 10 bytes to the right of 30-byte region 41 // CHECK40: is located 10 bytes to the right of 30-byte region
32 // 42 //
33 // CHECK80: allocated heap chunk; size: 32 offset: 16 43 // CHECK80: allocated heap chunk; size: 32 offset: 16