[compiler-rt] 016e604 - sanitizer_common: guard the wcslen interceptor code with SANITIZER_INTERCEPT_WCSLEN

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 23:44:03 PDT 2023


Author: Thurston Dang
Date: 2023-05-19T06:37:45Z
New Revision: 016e604f6e1680588160008ba10618f58097e57e

URL: https://github.com/llvm/llvm-project/commit/016e604f6e1680588160008ba10618f58097e57e
DIFF: https://github.com/llvm/llvm-project/commit/016e604f6e1680588160008ba10618f58097e57e.diff

LOG: sanitizer_common: guard the wcslen interceptor code with SANITIZER_INTERCEPT_WCSLEN

This patch adds the #if SANITIZER_INTERCEPT_ guard for wcslen, similarly to how all the other
functions are guarded. It was the only missing SANITIZER_INTERCEPT_ guard [1].

This missing guard was discovered while investigating the stage2/hwasan check failure of https://reviews.llvm.org/D150708 ("hwasan: lay groundwork for importing subset of sanitizer_common interceptors [NFC]"), that was seen in https://lab.llvm.org/buildbot/#/builders/236/builds/4069. llvm_build_hwasan/unittests/ADT/./ADTTests had crashed with a backtrace of:
...
A disassembly of the binary showed that wcslen interception was present (since it was not guarded by SANITIZER_INTERCEPT_WCSLEN); howver, since INIT_WCSLEN was not called, REAL(wcslen) was null, resulting in the null pointer dereference.

[1] I checked this using "egrep '^#[ ]*define[ ]+(INIT_.*)' sanitizer_common_interceptors.inc | tr -s ' ' | sed -r 's/^# /#/' | cut -d ' ' -f 2 | sort | uniq -c | grep -v '^[ ]*2[ ]'"
The other matches are {INIT_PTHREAD_SETNAME_NP, INIT_QSORT, INIT_SHA2_INTECEPTORS(LEN), INIT_TLS_GET_ADDR, INIT_WAIT4}, which all have good reasons for not having exactly two cases.

Differential Revision: https://reviews.llvm.org/D150909

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index bc31627ccca59..01f28754ba8ad 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7176,6 +7176,7 @@ INTERCEPTOR(int, mprobe, void *ptr) {
 }
 #endif
 
+#if SANITIZER_INTERCEPT_WCSLEN
 INTERCEPTOR(SIZE_T, wcslen, const wchar_t *s) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, wcslen, s);
@@ -7194,6 +7195,9 @@ INTERCEPTOR(SIZE_T, wcsnlen, const wchar_t *s, SIZE_T n) {
 #define INIT_WCSLEN                  \
   COMMON_INTERCEPT_FUNCTION(wcslen); \
   COMMON_INTERCEPT_FUNCTION(wcsnlen);
+#else
+#define INIT_WCSLEN
+#endif
 
 #if SANITIZER_INTERCEPT_WCSCAT
 INTERCEPTOR(wchar_t *, wcscat, wchar_t *dst, const wchar_t *src) {

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index cce4b2c3284b2..33ac3871e0add 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -494,6 +494,7 @@
 #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
 #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
 #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
+#define SANITIZER_INTERCEPT_WCSLEN SI_POSIX
 #define SANITIZER_INTERCEPT_WCSCAT SI_POSIX
 #define SANITIZER_INTERCEPT_WCSDUP SI_POSIX
 #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA)


        


More information about the llvm-commits mailing list