[compiler-rt] 6396a44 - Revert "SIGSEGV in Sanitizer INTERCEPTOR of strstr function."
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 5 21:28:06 PST 2022
Author: Vitaly Buka
Date: 2022-01-05T21:28:01-08:00
New Revision: 6396a4436145930f1bf0171219214c9f202019be
URL: https://github.com/llvm/llvm-project/commit/6396a4436145930f1bf0171219214c9f202019be
DIFF: https://github.com/llvm/llvm-project/commit/6396a4436145930f1bf0171219214c9f202019be.diff
LOG: Revert "SIGSEGV in Sanitizer INTERCEPTOR of strstr function."
Breaks Asan on Fuchsia's and ubsan with gcc.
This reverts commit 685c94c6cbba4f2bf076b01fd3e0dcb4b1425b53.
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
compiler-rt/test/sanitizer_common/TestCases/strstr.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 4cb4d4a59f694..b0ab08dff1db2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -575,12 +575,10 @@ INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, SIZE_T size) {
#if SANITIZER_INTERCEPT_STRSTR || SANITIZER_INTERCEPT_STRCASESTR
static inline void StrstrCheck(void *ctx, char *r, const char *s1,
const char *s2) {
- uptr len2 = internal_strlen(s2);
- COMMON_INTERCEPTOR_READ_RANGE(ctx, s2, len2 + 1);
- if (len2 == 0 && !common_flags()->strict_string_checks)
- return;
- uptr len1 = internal_strlen(s1);
- COMMON_INTERCEPTOR_READ_STRING(ctx, s1, r ? r - s1 + len2 : len1 + 1);
+ uptr len1 = internal_strlen(s1);
+ uptr len2 = internal_strlen(s2);
+ COMMON_INTERCEPTOR_READ_STRING(ctx, s1, r ? r - s1 + len2 : len1 + 1);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, s2, len2 + 1);
}
#endif
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
index d16e7bab69b54..d3076f0da4891 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
@@ -217,10 +217,8 @@ uptr internal_strnlen(const char *s, uptr maxlen) {
char *internal_strstr(const char *haystack, const char *needle) {
// This is O(N^2), but we are not using it in hot places.
- uptr len2 = internal_strlen(needle);
- if (len2 == 0)
- return const_cast<char *>(haystack);
uptr len1 = internal_strlen(haystack);
+ uptr len2 = internal_strlen(needle);
if (len1 < len2) return nullptr;
for (uptr pos = 0; pos <= len1 - len2; pos++) {
if (internal_memcmp(haystack + pos, needle, len2) == 0)
diff --git a/compiler-rt/test/sanitizer_common/TestCases/strstr.c b/compiler-rt/test/sanitizer_common/TestCases/strstr.c
index d6cff1b424fd4..2089ac7b5fcbd 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/strstr.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/strstr.c
@@ -8,9 +8,5 @@ int main(int argc, char **argv) {
char s2[] = "b";
r = strstr(s1, s2);
assert(r == s1 + 1);
- char *s3 = NULL;
- char *s4 = "";
- char *p = strstr(s3, s4);
- assert(p == NULL);
return 0;
}
More information about the llvm-commits
mailing list