1// Checks how we print the developer note "hwasan_dev_note_heap_rb_distance".
2// RUN: %clang_hwasan %s -o %t
3// RUN: not %run %t 10 2>&1 | FileCheck %s --check-prefix=D10
4// RUN: not %run %t 42 2>&1 | FileCheck %s --check-prefix=D42
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <sanitizer/hwasan_interface.h>
9
10
11void *p[100];
12
13int main(int argc, char **argv) {
14 __hwasan_enable_allocator_tagging();
15 int distance = argc >= 2 ? atoi(nptr: argv[1]) : 1;
16 for (int i = 0; i < 100; i++)
17 p[i] = malloc(size: i);
18 for (int i = 0; i < 100; i++)
19 free(ptr: p[i]);
20
21 *(int*)p[distance] = 0;
22}
23
24// D10: hwasan_dev_note_heap_rb_distance: 90 1023
25// D42: hwasan_dev_note_heap_rb_distance: 58 1023
26

source code of compiler-rt/test/hwasan/TestCases/uaf_with_rb_distance.c