[compiler-rt] r185428 - [sanitizer] Fix GLOB_NOMATCH behaviour and refactor the interceptor a bit.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Tue Jul 2 07:08:53 PDT 2013


Author: eugenis
Date: Tue Jul  2 09:08:52 2013
New Revision: 185428

URL: http://llvm.org/viewvc/llvm-project?rev=185428&view=rev
Log:
[sanitizer] Fix GLOB_NOMATCH behaviour and refactor the interceptor a bit.

Added:
    compiler-rt/trunk/lib/msan/lit_tests/Linux/glob_nomatch.cc   (with props)
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Added: compiler-rt/trunk/lib/msan/lit_tests/Linux/glob_nomatch.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/Linux/glob_nomatch.cc?rev=185428&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/Linux/glob_nomatch.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/Linux/glob_nomatch.cc Tue Jul  2 09:08:52 2013
@@ -0,0 +1,21 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t %p
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t %p
+
+#include <assert.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[]) {
+  assert(argc == 2);
+  char buf[1024];
+  snprintf(buf, sizeof(buf), "%s/%s", argv[1], "glob_test_root/*c");
+
+  glob_t globbuf;
+  int res = glob(buf, 0, 0, &globbuf);
+  assert(res == GLOB_NOMATCH);
+  assert(globbuf.gl_pathc == 0);
+  if (globbuf.gl_pathv == 0)
+    exit(0);
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/Linux/glob_nomatch.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

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=185428&r1=185427&r2=185428&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Jul  2 09:08:52 2013
@@ -738,18 +738,13 @@ INTERCEPTOR(int, setitimer, int which, c
 #define INIT_GETITIMER
 #endif
 
-
 #if SANITIZER_INTERCEPT_GLOB
-struct sanitizer_glob_t {
-  SIZE_T gl_pathc;
-  char **gl_pathv;
-};
-
-static void unpoison_glob_t(void *ctx, sanitizer_glob_t *pglob) {
+static void unpoison_glob_t(void *ctx, __sanitizer_glob_t *pglob) {
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pglob, sizeof(*pglob));
   // +1 for NULL pointer at the end.
-  COMMON_INTERCEPTOR_WRITE_RANGE(
-      ctx, pglob->gl_pathv, (pglob->gl_pathc + 1) * sizeof(*pglob->gl_pathv));
+  if (pglob->gl_pathv)
+    COMMON_INTERCEPTOR_WRITE_RANGE(
+        ctx, pglob->gl_pathv, (pglob->gl_pathc + 1) * sizeof(*pglob->gl_pathv));
   for (SIZE_T i = 0; i < pglob->gl_pathc; ++i) {
     char *p = pglob->gl_pathv[i];
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, REAL(strlen)(p) + 1);
@@ -758,32 +753,29 @@ static void unpoison_glob_t(void *ctx, s
 
 INTERCEPTOR(int, glob, const char *pattern, int flags,
             int (*errfunc)(const char *epath, int eerrno),
-            sanitizer_glob_t *pglob) {
+            __sanitizer_glob_t *pglob) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, glob, pattern, flags, errfunc, pglob);
   int res = REAL(glob)(pattern, flags, errfunc, pglob);
-  if (res == 0)
-    unpoison_glob_t(ctx, pglob);
+  if ((!res || res == glob_nomatch) && pglob) unpoison_glob_t(ctx, pglob);
   return res;
 }
 
 INTERCEPTOR(int, glob64, const char *pattern, int flags,
             int (*errfunc)(const char *epath, int eerrno),
-            sanitizer_glob_t *pglob) {
+            __sanitizer_glob_t *pglob) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, glob64, pattern, flags, errfunc, pglob);
   int res = REAL(glob64)(pattern, flags, errfunc, pglob);
-  if (res == 0)
-    unpoison_glob_t(ctx, pglob);
+  if ((!res || res == glob_nomatch) && pglob) unpoison_glob_t(ctx, pglob);
   return res;
 }
-#define INIT_GLOB                               \
-  INTERCEPT_FUNCTION(glob);                     \
+#define INIT_GLOB           \
+  INTERCEPT_FUNCTION(glob); \
   INTERCEPT_FUNCTION(glob64);
-#else // SANITIZER_INTERCEPT_GLOB
+#else  // SANITIZER_INTERCEPT_GLOB
 #define INIT_GLOB
-#endif // SANITIZER_INTERCEPT_GLOB
-
+#endif  // SANITIZER_INTERCEPT_GLOB
 
 #if SANITIZER_INTERCEPT_WAIT
 // According to sys/wait.h, wait(), waitid(), waitpid() may have symbol version

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=185428&r1=185427&r2=185428&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 Jul  2 09:08:52 2013
@@ -58,6 +58,7 @@
 #endif
 
 #if SANITIZER_LINUX && !SANITIZER_ANDROID
+#include <glob.h>
 #include <net/if_ppp.h>
 #include <netax25/ax25.h>
 #include <netipx/ipx.h>
@@ -163,6 +164,10 @@ namespace __sanitizer {
   }
 
 #if SANITIZER_LINUX && !SANITIZER_ANDROID
+  int glob_nomatch = GLOB_NOMATCH;
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
   unsigned struct_user_regs_struct_sz = sizeof(struct user_regs_struct);
   unsigned struct_user_fpregs_struct_sz = sizeof(struct user_fpregs_struct);
 #if __WORDSIZE == 64
@@ -732,6 +737,11 @@ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi
 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
 
 COMPILER_CHECK(IOC_SIZE(0x12345678) == _IOC_SIZE(0x12345678));
+
+COMPILER_CHECK(sizeof(__sanitizer_glob_t) <= sizeof(glob_t));
+CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
+CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
+
 #endif
 
 CHECK_TYPE_SIZE(addrinfo);

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=185428&r1=185427&r2=185428&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 Jul  2 09:08:52 2013
@@ -181,6 +181,15 @@ namespace __sanitizer {
   };
 
 #if SANITIZER_LINUX && !SANITIZER_ANDROID
+  struct __sanitizer_glob_t {
+    uptr gl_pathc;
+    char **gl_pathv;
+  };
+
+  extern int glob_nomatch;
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
   extern unsigned struct_user_regs_struct_sz;
   extern unsigned struct_user_fpregs_struct_sz;
   extern unsigned struct_user_fpxregs_struct_sz;





More information about the llvm-commits mailing list