brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 829a82f Raw
62 lines · c
1// RUN: %clang_hwasan  %s -o %t2// RUN: not %run %t   5  10  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK53// RUN: not %run %t   7  10  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK74// RUN: not %run %t   8  20  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK85// RUN: not %run %t 295 300  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK2956// RUN: not %run %t   1 550 550 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK17 8// Full granule.9// RUN: not %run %t  32  20  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_FULL,CHECK3210 11#include <sanitizer/hwasan_interface.h>12#include <stdio.h>13#include <stdlib.h>14#include <string.h>15 16int main(int argc, char **argv) {17  __hwasan_enable_allocator_tagging();18  if (argc < 2) {19    fprintf(stderr, "Invalid number of arguments.");20    abort();21  }22  int read_offset = atoi(argv[1]);23  int size = atoi(argv[2]);24  int access_size = atoi(argv[3]);25  while (1) {26    char *volatile x = (char *)malloc(size);27    if (__hwasan_test_shadow(x, size + 1) == size)28      memset(x + read_offset, 0, access_size);29    free(x);30  }31 32  // CHECK_SMALL: WRITE of size {{26|550}} at {{.*}} tags: [[TAG:[0-9a-f]+]]/{{[0-9a-f]+}}([[TAG]]) (ptr/mem)33  // CHECK_FULL: WRITE of size 26 at {{.*}} tags: [[TAG:[0-9a-f]+]]/00 (ptr/mem)34 35  // CHECK5: Invalid access starting at offset 536  // CHECK5: is located 5 bytes inside a 10-byte region37  // CHECK7: Invalid access starting at offset 338  // CHECK7: is located 7 bytes inside a 10-byte region39  // CHECK8: Invalid access starting at offset 1240  // CHECK8: is located 8 bytes inside a 20-byte region41  // CHECK295: Invalid access starting at offset 542  // CHECK295: is located 295 bytes inside a 300-byte region43  // CHECK1: Invalid access starting at offset 54944  // CHECK1: is located 1 bytes inside a 550-byte region45 46  // CHECK32-NOT: Invalid access starting at offset47  // CHECK32: is located 12 bytes after a 20-byte region48 49  // CHECK-LABEL: Memory tags around the buggy address50  // CHECK5: =>{{.*}}[0a]51  // CHECK7: =>{{.*}}[0a]52  // CHECK8: =>{{.*}}[04]53  // CHECK295: =>{{.*}}[0c]54  // CHECK1: =>{{.*}}[06]55 56  // CHECK32: =>{{.*}}[00]57 58  // CHECK-LABEL: Tags for short granules around the buggy address59  // CHECK_SMALL: =>{{.*}}{{\[}}[[TAG]]{{\]}}60  // CHECK_FULL: =>{{.*}}[..]61}62