[compiler-rt] 2d743af - [msan] Unpoison trailing nullptr in wordexp interceptor

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 17:19:51 PDT 2021


Author: Vitaly Buka
Date: 2021-08-24T17:19:11-07:00
New Revision: 2d743af4e98211cc232902c8691ec988cf838d9e

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

LOG: [msan] Unpoison trailing nullptr in wordexp interceptor

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

Added: 
    

Modified: 
    compiler-rt/lib/msan/tests/msan_test.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/msan/tests/msan_test.cpp b/compiler-rt/lib/msan/tests/msan_test.cpp
index 7c9af6591787c..039da3cafe66c 100644
--- a/compiler-rt/lib/msan/tests/msan_test.cpp
+++ b/compiler-rt/lib/msan/tests/msan_test.cpp
@@ -3750,6 +3750,14 @@ TEST(MemorySanitizer, getgroups_negative) {
   ASSERT_EQ(-1, n);
 }
 
+TEST(MemorySanitizer, wordexp_empty) {
+  wordexp_t w;
+  int res = wordexp("", &w, 0);
+  ASSERT_EQ(0, res);
+  ASSERT_EQ(0U, w.we_wordc);
+  ASSERT_STREQ(nullptr, w.we_wordv[0]);
+}
+
 TEST(MemorySanitizer, wordexp) {
   wordexp_t w;
   int res = wordexp("a b c", &w, 0);

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index d967c1d936ee7..d008de84b29af 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -3998,9 +3998,8 @@ INTERCEPTOR(int, wordexp, char *s, __sanitizer_wordexp_t *p, int flags) {
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, sizeof(*p));
     uptr we_wordc =
         ((flags & wordexp_wrde_dooffs) ? p->we_offs : 0) + p->we_wordc;
-    if (we_wordc)
-      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->we_wordv,
-                                     sizeof(*p->we_wordv) * we_wordc);
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->we_wordv,
+                                   sizeof(*p->we_wordv) * (we_wordc + 1));
     for (uptr i = 0; i < we_wordc; ++i) {
       char *w = p->we_wordv[i];
       if (w) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, w, internal_strlen(w) + 1);


        


More information about the llvm-commits mailing list