Skip to content

Commit ddf4a9c

Browse files
authored
[test][HWASAN] Force interceptors tests for memcmp and bcmp call interceptor (#71215)
1 parent b169e7f commit ddf4a9c

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

compiler-rt/test/hwasan/TestCases/bcmp.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@
44
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
55
// REQUIRES: !android
66

7+
#include <assert.h>
78
#include <sanitizer/hwasan_interface.h>
89
#include <stdlib.h>
910
#include <string.h>
1011
#include <unistd.h>
1112

13+
__attribute__((no_sanitize("hwaddress"))) void
14+
ForceCallInterceptor(void *p, const void *a, size_t size) {
15+
assert(bcmp(p, a, size) == 0);
16+
}
17+
1218
int main(int argc, char **argv) {
1319
__hwasan_enable_allocator_tagging();
1420
char a[] = {static_cast<char>(argc), 2, 3, 4};
1521
int size = sizeof(a);
1622
char *p = (char *)malloc(size);
1723
memcpy(p, a, size);
1824
free(p);
19-
return bcmp(p, a, size);
25+
ForceCallInterceptor(p, a, size);
26+
return 0;
2027
// CHECK: HWAddressSanitizer: tag-mismatch on address
2128
// CHECK: READ of size 4
22-
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-3]]
29+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-4]]
2330
// CHECK: Cause: use-after-free
2431
// CHECK: freed by thread
25-
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-7]]
32+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-8]]
2633
// CHECK: previously allocated by thread
27-
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-11]]
34+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-12]]
2835
}

compiler-rt/test/hwasan/TestCases/memcmp.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@
33
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
44
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
55

6+
#include <assert.h>
67
#include <sanitizer/hwasan_interface.h>
78
#include <stdlib.h>
89
#include <string.h>
910
#include <unistd.h>
1011

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+
1117
int main(int argc, char **argv) {
1218
__hwasan_enable_allocator_tagging();
1319
char a[] = {static_cast<char>(argc), 2, 3, 4};
1420
int size = sizeof(a);
1521
char *p = (char *)malloc(size);
1622
memcpy(p, a, size);
1723
free(p);
18-
return memcmp(p, a, size);
24+
ForceCallInterceptor(p, a, size);
25+
return 0;
1926
// CHECK: HWAddressSanitizer: tag-mismatch on address
2027
// 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]]
2229
// CHECK: Cause: use-after-free
2330
// 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]]
2532
// 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]]
2734
}

0 commit comments

Comments
 (0)