File: malloc_bisect.c

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (26 lines) | stat: -rw-r--r-- 1,027 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// RUN: %clang_hwasan -O0 %s -o %t
// RUN: %env_hwasan_opts=malloc_bisect_left=0,malloc_bisect_right=0          not %run %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CRASH
// RUN: %env_hwasan_opts=malloc_bisect_left=1000,malloc_bisect_right=999         %run %t 2>&1
// RUN: %env_hwasan_opts=malloc_bisect_left=0,malloc_bisect_right=4294967295 not %run %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CRASH
// RUN: %env_hwasan_opts=malloc_bisect_left=0,malloc_bisect_right=4294967295,malloc_bisect_dump=1 not %run %t 2>&1 | \
// RUN:     FileCheck %s --check-prefixes=CRASH,DUMP

#include <stdlib.h>
#include <stdio.h>
#include <sanitizer/hwasan_interface.h>

int main() {
  __hwasan_enable_allocator_tagging();
  // DUMP: [alloc] {{.*}} 10{{$}}
  // DUMP: in main{{.*}}malloc_bisect.c
  char * volatile p = (char*)malloc(10);
  // CRASH: HWAddressSanitizer: tag-mismatch on address
  // CRASH: in main{{.*}}malloc_bisect.c
  char volatile x = p[16];
  free(p);
  __hwasan_disable_allocator_tagging();

  return 0;
}