223
|
1 // RUN: %clang_hwasan %s -o %t
|
236
|
2 // RUN: not %run %t 5 10 2>&1 | FileCheck %s --check-prefix=CHECK5
|
|
3 // RUN: not %run %t 7 10 2>&1 | FileCheck %s --check-prefix=CHECK7
|
|
4 // RUN: not %run %t 8 20 2>&1 | FileCheck %s --check-prefix=CHECK8
|
|
5 // RUN: not %run %t 32 20 2>&1 | FileCheck %s --check-prefix=CHECK32
|
223
|
6
|
|
7 #include <sanitizer/hwasan_interface.h>
|
|
8 #include <stdio.h>
|
|
9 #include <stdlib.h>
|
|
10 #include <string.h>
|
|
11
|
|
12 int main(int argc, char **argv) {
|
|
13 __hwasan_enable_allocator_tagging();
|
236
|
14 if (argc < 2) {
|
|
15 fprintf(stderr, "Invalid number of arguments.");
|
|
16 abort();
|
|
17 }
|
|
18 int read_offset = argc < 2 ? 5 : atoi(argv[1]);
|
|
19 int size = argc < 3 ? 10 : atoi(argv[2]);
|
|
20 char *volatile x = (char *)malloc(size);
|
|
21 memset(x + read_offset, 0, 26);
|
|
22 // CHECK5: Invalid access starting at offset 5
|
|
23 // CHECK5: is located 5 bytes inside a 10-byte region
|
|
24 // CHECK7: Invalid access starting at offset 3
|
|
25 // CHECK7: is located 7 bytes inside a 10-byte region
|
|
26 // CHECK8: Invalid access starting at offset 12
|
|
27 // CHECK8: is located 8 bytes inside a 20-byte region
|
|
28 // CHECK32: is located 12 bytes after a 20-byte region
|
223
|
29 free(x);
|
|
30 }
|