[compiler-rt] r191305 - [sanitizer] Intercept wordexp.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Tue Sep 24 07:38:22 PDT 2013


Author: eugenis
Date: Tue Sep 24 09:38:22 2013
New Revision: 191305

URL: http://llvm.org/viewvc/llvm-project?rev=191305&view=rev
Log:
[sanitizer] Intercept wordexp.

Modified:
    compiler-rt/trunk/lib/msan/tests/msan_test.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=191305&r1=191304&r2=191305&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Tue Sep 24 09:38:22 2013
@@ -49,6 +49,7 @@
 #include <pwd.h>
 #include <sys/socket.h>
 #include <netdb.h>
+#include <wordexp.h>
 
 #if defined(__i386__) || defined(__x86_64__)
 # include <emmintrin.h>
@@ -2400,6 +2401,16 @@ TEST(MemorySanitizer, getgroups) {
     EXPECT_NOT_POISONED(gids[i]);
 }
 
+TEST(MemorySanitizer, wordexp) {
+  wordexp_t w;
+  int res = wordexp("a b c", &w, 0);
+  ASSERT_EQ(0, res);
+  ASSERT_EQ(3, w.we_wordc);
+  ASSERT_STREQ("a", w.we_wordv[0]);
+  ASSERT_STREQ("b", w.we_wordv[1]);
+  ASSERT_STREQ("c", w.we_wordv[2]);
+}
+
 template<class T>
 static bool applySlt(T value, T shadow) {
   __msan_partial_poison(&value, &shadow, sizeof(T));

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=191305&r1=191304&r2=191305&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Sep 24 09:38:22 2013
@@ -1995,6 +1995,29 @@ INTERCEPTOR(int, ppoll, __sanitizer_poll
 #define INIT_PPOLL
 #endif
 
+#if SANITIZER_INTERCEPT_WORDEXP
+INTERCEPTOR(int, wordexp, char *s, __sanitizer_wordexp_t *p, int flags) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, wordexp, s, p, flags);
+  if (s) COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
+  int res = REAL(wordexp)(s, p, flags);
+  if (!res && p) {
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, sizeof(*p));
+    if (p->we_wordc)
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->we_wordv,
+                                     sizeof(*p->we_wordv) * p->we_wordc);
+    for (uptr i = 0; i < p->we_wordc; ++i) {
+      char *w = p->we_wordv[i];
+      if (w) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, w, REAL(strlen)(w) + 1);
+    }
+  }
+  return res;
+}
+#define INIT_WORDEXP INTERCEPT_FUNCTION(wordexp);
+#else
+#define INIT_WORDEXP
+#endif
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCMP;                             \
   INIT_STRNCMP;                            \
@@ -2063,4 +2086,5 @@ INTERCEPTOR(int, ppoll, __sanitizer_poll
   INIT_SCANDIR64;                          \
   INIT_GETGROUPS;                          \
   INIT_POLL;                               \
-  INIT_PPOLL;
+  INIT_PPOLL;                              \
+  INIT_WORDEXP;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=191305&r1=191304&r2=191305&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Sep 24 09:38:22 2013
@@ -118,5 +118,6 @@
 # define SANITIZER_INTERCEPT_GETGROUPS SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_POLL SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_PPOLL SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_WORDEXP SI_MAC || SI_LINUX_NOT_ANDROID
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=191305&r1=191304&r2=191305&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Tue Sep 24 09:38:22 2013
@@ -42,6 +42,7 @@
 #include <termios.h>
 #include <time.h>
 #include <wchar.h>
+#include <wordexp.h>
 
 #if SANITIZER_LINUX
 #include <utime.h>
@@ -874,4 +875,9 @@ CHECK_TYPE_SIZE(__kernel_loff_t);
 CHECK_TYPE_SIZE(__kernel_fd_set);
 #endif
 
+CHECK_TYPE_SIZE(wordexp_t);
+CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
+CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
+CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
+
 #endif  // SANITIZER_LINUX || SANITIZER_MAC

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=191305&r1=191304&r2=191305&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Tue Sep 24 09:38:22 2013
@@ -286,6 +286,12 @@ namespace __sanitizer {
 
   extern unsigned path_max;
 
+  struct __sanitizer_wordexp_t {
+    uptr we_wordc;
+    char **we_wordv;
+    uptr we_offs;
+  };
+
 #if SANITIZER_LINUX && !SANITIZER_ANDROID && \
       (defined(__i386) || defined (__x86_64))  // NOLINT
   extern unsigned struct_user_regs_struct_sz;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=191305&r1=191304&r2=191305&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Tue Sep 24 09:38:22 2013
@@ -361,6 +361,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_scandir]                  = "  scandir                         ";
   name[StatInt_scandir64]                = "  scandir64                       ";
   name[StatInt_getgroups]                = "  getgroups                       ";
+  name[StatInt_wordexp]                  = "  wordexp                         ";
 
   name[StatAnnotation]                   = "Dynamic annotations               ";
   name[StatAnnotateHappensBefore]        = "  HappensBefore                   ";

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=191305&r1=191304&r2=191305&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Tue Sep 24 09:38:22 2013
@@ -356,6 +356,7 @@ enum StatType {
   StatInt_scandir,
   StatInt_scandir64,
   StatInt_getgroups,
+  StatInt_wordexp,
 
   // Dynamic annotations.
   StatAnnotation,





More information about the llvm-commits mailing list