[compiler-rt] r195839 - [sanitizer] Intercept __xpg_strerror_r.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Wed Nov 27 04:29:11 PST 2013


Author: eugenis
Date: Wed Nov 27 06:29:10 2013
New Revision: 195839

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

Added:
    compiler-rt/trunk/lib/msan/lit_tests/strerror_r-non-gnu.c   (with props)
Modified:
    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

Added: compiler-rt/trunk/lib/msan/lit_tests/strerror_r-non-gnu.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/strerror_r-non-gnu.c?rev=195839&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/strerror_r-non-gnu.c (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/strerror_r-non-gnu.c Wed Nov 27 06:29:10 2013
@@ -0,0 +1,18 @@
+// RUN: %clang_msan -std=c99 -O0 -g %s -o %t && %t
+
+// strerror_r under a weird set of circumstances can be redirected to
+// __xpg_strerror_r. Test that MSan handles this correctly.
+
+#define _POSIX_C_SOURCE 200112
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+int main() {
+  char buf[1000];
+  int res = strerror_r(EINVAL, buf, sizeof(buf));
+  assert(!res);
+  volatile int z = strlen(buf);
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/strerror_r-non-gnu.c
------------------------------------------------------------------------------
    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=195839&r1=195838&r2=195839&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Nov 27 06:29:10 2013
@@ -1848,6 +1848,21 @@ INTERCEPTOR(char *, strerror_r, int errn
 #define INIT_STRERROR_R
 #endif
 
+#if SANITIZER_INTERCEPT_XPG_STRERROR_R
+INTERCEPTOR(int, __xpg_strerror_r, int errnum, char *buf, SIZE_T buflen) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, __xpg_strerror_r, errnum, buf, buflen);
+  int res = REAL(__xpg_strerror_r)(errnum, buf, buflen);
+  // This version always returns a null-terminated string.
+  if (buf && buflen)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, REAL(strlen)(buf) + 1);
+  return res;
+}
+#define INIT_XPG_STRERROR_R COMMON_INTERCEPT_FUNCTION(__xpg_strerror_r);
+#else
+#define INIT_XPG_STRERROR_R
+#endif
+
 #if SANITIZER_INTERCEPT_SCANDIR
 typedef int (*scandir_filter_f)(const struct __sanitizer_dirent *);
 typedef int (*scandir_compar_f)(const struct __sanitizer_dirent **,
@@ -2895,6 +2910,7 @@ INTERCEPTOR(SSIZE_T, getdelim, char **li
   INIT_SCHED_GETAFFINITY;                  \
   INIT_STRERROR;                           \
   INIT_STRERROR_R;                         \
+  INIT_XPG_STRERROR_R;                     \
   INIT_SCANDIR;                            \
   INIT_SCANDIR64;                          \
   INIT_GETGROUPS;                          \

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=195839&r1=195838&r2=195839&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Nov 27 06:29:10 2013
@@ -120,6 +120,7 @@
 # define SANITIZER_INTERCEPT_SCHED_GETAFFINITY SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_STRERROR SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_STRERROR_R SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_XPG_STRERROR_R SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_SCANDIR SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_SCANDIR64 SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_GETGROUPS SI_NOT_WINDOWS

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=195839&r1=195838&r2=195839&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Wed Nov 27 06:29:10 2013
@@ -361,6 +361,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_sched_getaffinity]        = "  sched_getaffinity               ";
   name[StatInt_strerror]                 = "  strerror                        ";
   name[StatInt_strerror_r]               = "  strerror_r                      ";
+  name[StatInt___xpg_strerror_r]         = "  __xpg_strerror_r                ";
   name[StatInt_scandir]                  = "  scandir                         ";
   name[StatInt_scandir64]                = "  scandir64                       ";
   name[StatInt_getgroups]                = "  getgroups                       ";

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=195839&r1=195838&r2=195839&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Wed Nov 27 06:29:10 2013
@@ -356,6 +356,7 @@ enum StatType {
   StatInt_sched_getaffinity,
   StatInt_strerror,
   StatInt_strerror_r,
+  StatInt___xpg_strerror_r,
   StatInt_scandir,
   StatInt_scandir64,
   StatInt_getgroups,





More information about the llvm-commits mailing list