brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 093a017 Raw
33 lines · cpp
1// RUN: %clangxx_hwasan %s -o %t2// RUN: %env_hwasan_opts=halt_on_error=0 not %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST --check-prefixes=CHECK,RECOVER3// RUN: %env_hwasan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST4 5#include <sanitizer/hwasan_interface.h>6#include <stdio.h>7#include <stdlib.h>8#include <string.h>9#include <unistd.h>10 11__attribute__((no_sanitize("hwaddress"))) void12ForceCallInterceptor(void *p, int c, size_t size) {13  memset(p, c, size) == nullptr;14}15 16int main(int argc, char **argv) {17  __hwasan_enable_allocator_tagging();18  char a[] = {static_cast<char>(argc), 2, 3, 4};19  int size = sizeof(a);20  char *volatile p = (char *)malloc(size);21  void *volatile p2 = p;22  for (int i = 0; p2 == p; p2 = __hwasan_tag_pointer(p, ++i)) {23  }24  ForceCallInterceptor(p2, 0, size);25  free(p);26  fprintf(stderr, "RETURN_FROM_TEST\n");27  return 0;28  // CHECK: HWAddressSanitizer: tag-mismatch on address29  // CHECK: WRITE of size 430  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memset-recover.cpp:[[@LINE-28]]31  // RECOVER: RETURN_FROM_TEST32}33