[compiler-rt] c046cff - [msan] strsignal interceptor

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 17 18:13:44 PST 2022


Author: Vitaly Buka
Date: 2022-02-17T18:13:35-08:00
New Revision: c046cff1cf11d63aa0f5483b758464f989fbc029

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

LOG: [msan] strsignal interceptor

Reviewed By: kstoimenov

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

Added: 
    compiler-rt/test/msan/strsignal.cpp

Modified: 
    compiler-rt/lib/msan/msan_interceptors.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index 5317af6982a03..dbe18ce37509e 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1436,6 +1436,15 @@ static uptr signal_impl(int signo, uptr cb) {
 #include "sanitizer_common/sanitizer_common_syscalls.inc"
 #include "sanitizer_common/sanitizer_syscalls_netbsd.inc"
 
+INTERCEPTOR(const char *, strsignal, int sig) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, strsignal, sig);
+  const char *res = REAL(strsignal)(sig);
+  if (res)
+    __msan_unpoison(res, internal_strlen(res) + 1);
+  return res;
+}
+
 struct dlinfo {
   char *dli_fname;
   void *dli_fbase;
@@ -1699,6 +1708,7 @@ void InitializeInterceptors() {
   INTERCEPT_FUNCTION(gethostname);
   MSAN_MAYBE_INTERCEPT_EPOLL_WAIT;
   MSAN_MAYBE_INTERCEPT_EPOLL_PWAIT;
+  INTERCEPT_FUNCTION(strsignal);
   INTERCEPT_FUNCTION(dladdr);
   INTERCEPT_FUNCTION(dlerror);
   INTERCEPT_FUNCTION(dl_iterate_phdr);

diff  --git a/compiler-rt/test/msan/strsignal.cpp b/compiler-rt/test/msan/strsignal.cpp
new file mode 100644
index 0000000000000..62b68e00b9e71
--- /dev/null
+++ b/compiler-rt/test/msan/strsignal.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+  const char *p = strsignal(SIGSEGV);
+  assert(p);
+  printf("%s %zu\n", p, strlen(p));
+  return 0;
+}


        


More information about the llvm-commits mailing list