summaryrefslogtreecommitdiff
path: root/compiler-rt/lib/dfsan/dfsan_custom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/lib/dfsan/dfsan_custom.cpp')
-rw-r--r--compiler-rt/lib/dfsan/dfsan_custom.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index 84f0271b15e0..1acd2d47d154 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -84,7 +84,13 @@ SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strchr(const char *s, int c,
*ret_label = dfsan_union(dfsan_read_label(s, i + 1),
dfsan_union(s_label, c_label));
}
- return s[i] == 0 ? nullptr : const_cast<char *>(s+i);
+
+ // If s[i] is the \0 at the end of the string, and \0 is not the
+ // character we are searching for, then return null.
+ if (s[i] == 0 && c != 0) {
+ return nullptr;
+ }
+ return const_cast<char *>(s + i);
}
}
}
@@ -151,14 +157,17 @@ SANITIZER_INTERFACE_ATTRIBUTE int
__dfsw_strcasecmp(const char *s1, const char *s2, dfsan_label s1_label,
dfsan_label s2_label, dfsan_label *ret_label) {
for (size_t i = 0;; ++i) {
- if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0) {
+ char s1_lower = tolower(s1[i]);
+ char s2_lower = tolower(s2[i]);
+
+ if (s1_lower != s2_lower || s1[i] == 0 || s2[i] == 0) {
if (flags().strict_data_dependencies) {
*ret_label = 0;
} else {
*ret_label = dfsan_union(dfsan_read_label(s1, i + 1),
dfsan_read_label(s2, i + 1));
}
- return s1[i] - s2[i];
+ return s1_lower - s2_lower;
}
}
return 0;
@@ -206,15 +215,17 @@ __dfsw_strncasecmp(const char *s1, const char *s2, size_t n,
}
for (size_t i = 0;; ++i) {
- if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0 ||
- i == n - 1) {
+ char s1_lower = tolower(s1[i]);
+ char s2_lower = tolower(s2[i]);
+
+ if (s1_lower != s2_lower || s1[i] == 0 || s2[i] == 0 || i == n - 1) {
if (flags().strict_data_dependencies) {
*ret_label = 0;
} else {
*ret_label = dfsan_union(dfsan_read_label(s1, i + 1),
dfsan_read_label(s2, i + 1));
}
- return s1[i] - s2[i];
+ return s1_lower - s2_lower;
}
}
return 0;