brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 40dc3de Raw
33 lines · cpp
1// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s2// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s3// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s4// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s5 6#include <sanitizer/hwasan_interface.h>7#include <stdlib.h>8#include <string.h>9#include <unistd.h>10 11__attribute__((no_sanitize("hwaddress"))) void12ForceCallInterceptor(void *p, const void *a, size_t size) {13  memmove(p, a, size);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  free(p);22  ForceCallInterceptor(p, a, size);23  return 0;24  // CHECK: HWAddressSanitizer: tag-mismatch on address25  // CHECK: WRITE of size 426  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memmove.cpp:[[@LINE-4]]27  // CHECK: Cause: use-after-free28  // CHECK: freed by thread29  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memmove.cpp:[[@LINE-8]]30  // CHECK: previously allocated by thread31  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memmove.cpp:[[@LINE-11]]32}33