Skip to content

Commit 559f919

Browse files
committed
[DFSan] Add bcmp wrapper.
Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D87801
1 parent d5ce823 commit 559f919

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

compiler-rt/lib/dfsan/dfsan_custom.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
129129
return 0;
130130
}
131131

132+
SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_bcmp(const void *s1, const void *s2,
133+
size_t n, dfsan_label s1_label,
134+
dfsan_label s2_label,
135+
dfsan_label n_label,
136+
dfsan_label *ret_label) {
137+
return __dfsw_memcmp(s1, s2, n, s1_label, s2_label, n_label, ret_label);
138+
}
139+
132140
DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strcmp, uptr caller_pc,
133141
const char *s1, const char *s2,
134142
dfsan_label s1_label, dfsan_label s2_label)

compiler-rt/lib/dfsan/done_abilist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ fun:strtoull=custom
183183

184184
# Functions that produce an output that is computed from the input, but is not
185185
# necessarily data dependent.
186+
fun:bcmp=custom
186187
fun:memchr=custom
187188
fun:memcmp=custom
188189
fun:strcasecmp=custom

compiler-rt/test/dfsan/custom.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
#include <pwd.h>
1818
#include <sched.h>
1919
#include <signal.h>
20-
#include <stdio.h>
2120
#include <stdint.h>
21+
#include <stdio.h>
2222
#include <stdlib.h>
2323
#include <string.h>
24-
#include <sys/select.h>
24+
#include <strings.h>
2525
#include <sys/resource.h>
26+
#include <sys/select.h>
2627
#include <sys/stat.h>
2728
#include <sys/time.h>
2829
#include <sys/types.h>
@@ -86,6 +87,24 @@ void test_memcmp() {
8687
#endif
8788
}
8889

90+
void test_bcmp() {
91+
char str1[] = "str1", str2[] = "str2";
92+
dfsan_set_label(i_label, &str1[3], 1);
93+
dfsan_set_label(j_label, &str2[3], 1);
94+
95+
int rv = bcmp(str1, str2, sizeof(str1));
96+
assert(rv != 0);
97+
#ifdef STRICT_DATA_DEPENDENCIES
98+
ASSERT_ZERO_LABEL(rv);
99+
#else
100+
ASSERT_LABEL(rv, i_j_label);
101+
#endif
102+
103+
rv = bcmp(str1, str2, sizeof(str1) - 2);
104+
assert(rv == 0);
105+
ASSERT_ZERO_LABEL(rv);
106+
}
107+
89108
void test_memcpy() {
90109
char str1[] = "str1";
91110
char str2[sizeof(str1)];
@@ -967,6 +986,7 @@ int main(void) {
967986
assert(i_j_label != j_label);
968987
assert(i_j_label != k_label);
969988

989+
test_bcmp();
970990
test_calloc();
971991
test_clock_gettime();
972992
test_ctime_r();

0 commit comments

Comments
 (0)