36 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// REQUIRES: !android6 7#include <assert.h>8#include <sanitizer/hwasan_interface.h>9#include <stdlib.h>10#include <string.h>11#include <unistd.h>12 13__attribute__((no_sanitize("hwaddress"))) void14ForceCallInterceptor(void *p, const void *a, size_t size) {15 assert(bcmp(p, a, size) == 0);16}17 18int main(int argc, char **argv) {19 __hwasan_enable_allocator_tagging();20 char a[] = {static_cast<char>(argc), 2, 3, 4};21 int size = sizeof(a);22 char *p = (char *)malloc(size);23 memcpy(p, a, size);24 free(p);25 ForceCallInterceptor(p, a, size);26 return 0;27 // CHECK: HWAddressSanitizer: tag-mismatch on address28 // CHECK: READ of size 429 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-4]]30 // CHECK: Cause: use-after-free31 // CHECK: freed by thread32 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-8]]33 // CHECK: previously allocated by thread34 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-12]]35}36