Skip to content

Commit ff1329e

Browse files
authored
[HWASAN] Add bcmp interceptor (#69257)
1 parent b225934 commit ff1329e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler-rt/lib/hwasan/hwasan_platform_interceptors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
// #undef SANITIZER_INTERCEPT_MEMCMP
6969
// #define SANITIZER_INTERCEPT_MEMCMP 0
7070

71-
#undef SANITIZER_INTERCEPT_BCMP
72-
#define SANITIZER_INTERCEPT_BCMP 0
71+
// #undef SANITIZER_INTERCEPT_BCMP
72+
// #define SANITIZER_INTERCEPT_BCMP 0
7373

7474
#undef SANITIZER_INTERCEPT_STRNDUP
7575
#define SANITIZER_INTERCEPT_STRNDUP 0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2+
// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3+
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4+
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5+
6+
#include <sanitizer/hwasan_interface.h>
7+
#include <stdlib.h>
8+
#include <string.h>
9+
#include <unistd.h>
10+
11+
int main(int argc, char **argv) {
12+
__hwasan_enable_allocator_tagging();
13+
char a[] = {static_cast<char>(argc), 2, 3, 4};
14+
int size = sizeof(a);
15+
char *p = (char *)malloc(size);
16+
memcpy(p, a, size);
17+
free(p);
18+
return bcmp(p, a, size);
19+
// CHECK: HWAddressSanitizer: tag-mismatch on address
20+
// CHECK: READ of size 4
21+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-3]]
22+
// CHECK: Cause: use-after-free
23+
// CHECK: freed by thread
24+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-7]]
25+
// CHECK: previously allocated by thread
26+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-11]]
27+
}

0 commit comments

Comments
 (0)