[compiler-rt] r193415 - [sanitizer] Intercept tmpnam, tmpnam_r, tempnam.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Fri Oct 25 08:51:49 PDT 2013


Author: eugenis
Date: Fri Oct 25 10:51:48 2013
New Revision: 193415

URL: http://llvm.org/viewvc/llvm-project?rev=193415&view=rev
Log:
[sanitizer] Intercept tmpnam, tmpnam_r, tempnam.

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/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=193415&r1=193414&r2=193415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Fri Oct 25 10:51:48 2013
@@ -2635,6 +2635,19 @@ TEST(MemorySanitizer, pthread_cond_wait)
   pthread_cond_destroy(&cond);
 }
 
+TEST(MemorySanitizer, tmpnam) {
+  char s[L_tmpnam];
+  char *res = tmpnam(s);
+  ASSERT_EQ(s, res);
+  EXPECT_NOT_POISONED(strlen(res));
+}
+
+TEST(MemorySanitizer, tempnam) {
+  char *res = tempnam(NULL, "zzz");
+  EXPECT_NOT_POISONED(strlen(res));
+  free(res);
+}
+
 TEST(MemorySanitizer, posix_memalign) {
   void *p;
   EXPECT_POISONED(p);

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=193415&r1=193414&r2=193415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Oct 25 10:51:48 2013
@@ -2609,6 +2609,53 @@ INTERCEPTOR(int, pthread_attr_getaffinit
 #define INIT_PTHREAD_ATTR_GETAFFINITY_NP
 #endif
 
+#if SANITIZER_INTERCEPT_TMPNAM
+INTERCEPTOR(char *, tmpnam, char *s) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, tmpnam, s);
+  char *res = REAL(tmpnam)(s);
+  if (res) {
+    if (s)
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, s, REAL(strlen)(s) + 1);
+    else
+      COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, res, REAL(strlen)(res) + 1);
+  }
+  return res;
+}
+#define INIT_TMPNAM INTERCEPT_FUNCTION(tmpnam);
+#else
+#define INIT_TMPNAM
+#endif
+
+#if SANITIZER_INTERCEPT_TMPNAM_R
+INTERCEPTOR(char *, tmpnam_r, char *s) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, tmpnam_r, s);
+  char *res = REAL(tmpnam_r)(s);
+  if (res && s) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, s, REAL(strlen)(s) + 1);
+  return res;
+}
+#define INIT_TMPNAM_R INTERCEPT_FUNCTION(tmpnam_r);
+#else
+#define INIT_TMPNAM_R
+#endif
+
+#if SANITIZER_INTERCEPT_TEMPNAM
+INTERCEPTOR(char *, tempnam, char *dir, char *pfx) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, tempnam, dir, pfx);
+  if (dir) COMMON_INTERCEPTOR_READ_RANGE(ctx, dir, REAL(strlen)(dir) + 1);
+  if (pfx) COMMON_INTERCEPTOR_READ_RANGE(ctx, pfx, REAL(strlen)(pfx) + 1);
+  char *res = REAL(tempnam)(dir, pfx);
+  if (res) COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, res, REAL(strlen)(res) + 1);
+  return res;
+}
+#define INIT_TEMPNAM INTERCEPT_FUNCTION(tempnam);
+#else
+#define INIT_TEMPNAM
+#endif
+
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCMP;                             \
   INIT_STRNCMP;                            \
@@ -2707,4 +2754,7 @@ INTERCEPTOR(int, pthread_attr_getaffinit
   INIT_PTHREAD_ATTR_GET;                   \
   INIT_PTHREAD_ATTR_GETINHERITSCHED;       \
   INIT_PTHREAD_ATTR_GETAFFINITY_NP;        \
+  INIT_TMPNAM;                             \
+  INIT_TMPNAM_R;                           \
+  INIT_TEMPNAM;                            \
 /**/

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=193415&r1=193414&r2=193415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Oct 25 10:51:48 2013
@@ -141,6 +141,9 @@
 # define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
   SI_MAC || SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_TMPNAM SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_TMPNAM_R SI_MAC || SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_TEMPNAM SI_NOT_WINDOWS
 
 # define SANITIZER_INTERCEPT__EXIT SI_LINUX
 

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=193415&r1=193414&r2=193415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Fri Oct 25 10:51:48 2013
@@ -394,6 +394,9 @@ void StatOutput(u64 *stat) {
   name[StatInt_ether_line]               = "  ether_line                      ";
   name[StatInt_shmctl]                   = "  shmctl                          ";
   name[StatInt_random_r]                 = "  random_r                        ";
+  name[StatInt_tmpnam]                   = "  tmpnam                          ";
+  name[StatInt_tmpnam_r]                 = "  tmpnam_r                        ";
+  name[StatInt_tempnam]                  = "  tempnam                         ";
 
   name[StatInt_pthread_attr_getdetachstate]  = "  pthread_addr_getdetachstate     ";  // NOLINT
   name[StatInt_pthread_attr_getguardsize]    = "  pthread_addr_getguardsize       ";  // NOLINT

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=193415&r1=193414&r2=193415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Fri Oct 25 10:51:48 2013
@@ -389,6 +389,10 @@ enum StatType {
   StatInt_ether_line,
   StatInt_shmctl,
   StatInt_random_r,
+  StatInt_tmpnam,
+  StatInt_tmpnam_r,
+  StatInt_tempnam,
+
   StatInt_pthread_attr_getdetachstate,
   StatInt_pthread_attr_getguardsize,
   StatInt_pthread_attr_getschedparam,





More information about the llvm-commits mailing list