brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 154b698 Raw
37 lines · cpp
1// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST2// RUN: %clangxx_hwasan -O3 %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST3// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=0:symbolize=0 %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST --check-prefixes=CHECK,RECOVER4 5// UNSUPPORTED: android6 7#include <assert.h>8#include <errno.h>9#include <glob.h>10#include <malloc.h>11#include <stdio.h>12#include <string.h>13 14#include <sanitizer/hwasan_interface.h>15#include <sanitizer/linux_syscall_hooks.h>16 17/* Test the presence of __sanitizer_syscall_ in the tool runtime, and general18   sanity of their behaviour. */19 20int main(int argc, char *argv[]) {21  // lit.cfg.py currently sets 'disable_allocator_tagging=1'22  __hwasan_enable_allocator_tagging();23 24  char *buf = (char *)malloc(1000);25  assert(buf != NULL);26 27  __sanitizer_syscall_pre_recvmsg(0, buf - 1, 0);28  // CHECK: HWAddressSanitizer: tag-mismatch on address [[PTR:0x[a-f0-9]+]]29  // CHECK: Cause: heap-buffer-overflow30  // CHECK: [[PTR]] is located 1 bytes before a 1000-byte region31 32  free(buf);33  fprintf(stderr, "RETURN_FROM_TEST\n");34  // RECOVER: RETURN_FROM_TEST35  return 0;36}37