From 6396a4436145930f1bf0171219214c9f202019be Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 5 Jan 2022 21:25:26 -0800 Subject: [PATCH] Revert "SIGSEGV in Sanitizer INTERCEPTOR of strstr function." Breaks Asan on Fuchsia's and ubsan with gcc. This reverts commit 685c94c6cbba4f2bf076b01fd3e0dcb4b1425b53. --- .../lib/sanitizer_common/sanitizer_common_interceptors.inc | 10 ++++------ compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp | 4 +--- compiler-rt/test/sanitizer_common/TestCases/strstr.c | 4 ---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 4cb4d4a..b0ab08d 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 d16e7ba..d3076f0 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(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 d6cff1b..2089ac7 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; } -- 2.7.4