|
3 | 3 | // RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
|
4 | 4 | // RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
|
5 | 5 |
|
| 6 | +#include <assert.h> |
6 | 7 | #include <sanitizer/hwasan_interface.h>
|
7 | 8 | #include <stdlib.h>
|
8 | 9 | #include <string.h>
|
9 | 10 | #include <unistd.h>
|
10 | 11 |
|
| 12 | +__attribute__((no_sanitize("hwaddress"))) void |
| 13 | +ForceCallInterceptor(void *p, const void *a, size_t size) { |
| 14 | + assert(memcmp(p, a, size) == 0); |
| 15 | +} |
| 16 | + |
11 | 17 | int main(int argc, char **argv) {
|
12 | 18 | __hwasan_enable_allocator_tagging();
|
13 | 19 | char a[] = {static_cast<char>(argc), 2, 3, 4};
|
14 | 20 | int size = sizeof(a);
|
15 | 21 | char *p = (char *)malloc(size);
|
16 | 22 | memcpy(p, a, size);
|
17 | 23 | free(p);
|
18 |
| - return memcmp(p, a, size); |
| 24 | + ForceCallInterceptor(p, a, size); |
| 25 | + return 0; |
19 | 26 | // CHECK: HWAddressSanitizer: tag-mismatch on address
|
20 | 27 | // CHECK: READ of size 4
|
21 |
| - // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-3]] |
| 28 | + // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-4]] |
22 | 29 | // CHECK: Cause: use-after-free
|
23 | 30 | // CHECK: freed by thread
|
24 |
| - // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-7]] |
| 31 | + // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-8]] |
25 | 32 | // CHECK: previously allocated by thread
|
26 |
| - // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-11]] |
| 33 | + // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-12]] |
27 | 34 | }
|
0 commit comments