summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-07-30 12:46:59 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-07-30 12:46:59 +0000
commitda9fd2560324c659900079c06411f062ba7e46bb (patch)
tree5f17f2f417895f04f14a51b575b25c77d2c5b143
parentd8a1798b47e2e956338a3d6ff9c3e3ec0fcf1021 (diff)
downloadbcm5719-llvm-da9fd2560324c659900079c06411f062ba7e46bb.tar.gz
bcm5719-llvm-da9fd2560324c659900079c06411f062ba7e46bb.zip
[msan] Intercept confstr.
llvm-svn: 187412
-rw-r--r--compiler-rt/lib/msan/tests/msan_test.cc16
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc17
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.cc1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.h1
5 files changed, 35 insertions, 1 deletions
diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc
index a13f05d900d..1890db2b991 100644
--- a/compiler-rt/lib/msan/tests/msan_test.cc
+++ b/compiler-rt/lib/msan/tests/msan_test.cc
@@ -926,6 +926,22 @@ TEST(MemorySanitizer, get_current_dir_name) {
free(res);
}
+TEST(MemorySanitizer, confstr) {
+ char buf[3];
+ size_t res = confstr(_CS_PATH, buf, sizeof(buf));
+ ASSERT_GT(res, sizeof(buf));
+ EXPECT_NOT_POISONED(buf[0]);
+ EXPECT_NOT_POISONED(buf[sizeof(buf) - 1]);
+
+ char buf2[1000];
+ res = confstr(_CS_PATH, buf2, sizeof(buf2));
+ ASSERT_LT(res, sizeof(buf2));
+ EXPECT_NOT_POISONED(buf2[0]);
+ EXPECT_NOT_POISONED(buf2[res - 1]);
+ EXPECT_POISONED(buf2[res]);
+ ASSERT_EQ(res, strlen(buf2) + 1);
+}
+
TEST(MemorySanitizer, readdir) {
DIR *dir = opendir(".");
struct dirent *d = readdir(dir);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index e48b3922289..58dd044d309 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1747,6 +1747,20 @@ INTERCEPTOR(char *, canonicalize_file_name, const char *path) {
#define INIT_CANONICALIZE_FILE_NAME
#endif
+#if SANITIZER_INTERCEPT_CONFSTR
+INTERCEPTOR(SIZE_T, confstr, int name, char *buf, SIZE_T len) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, confstr, name, buf, len);
+ SIZE_T res = REAL(confstr)(name, buf, len);
+ if (buf && res)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, res < len ? res : len);
+ return res;
+}
+#define INIT_CONFSTR INTERCEPT_FUNCTION(confstr);
+#else
+#define INIT_CONFSTR
+#endif
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_STRCMP; \
INIT_STRNCMP; \
@@ -1805,4 +1819,5 @@ INTERCEPTOR(char *, canonicalize_file_name, const char *path) {
INIT_WCSNRTOMBS; \
INIT_TCGETATTR; \
INIT_REALPATH; \
- INIT_CANONICALIZE_FILE_NAME;
+ INIT_CANONICALIZE_FILE_NAME; \
+ INIT_CONFSTR;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index e07a134e169..a601c7f0054 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -109,5 +109,6 @@
# define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX
# define SANITIZER_INTERCEPT_REALPATH SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_CANONICALIZE_FILE_NAME SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_CONFSTR SI_MAC || SI_LINUX_NOT_ANDROID
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
index 5e8cc18ee79..fe0c09cf1f9 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
@@ -352,6 +352,7 @@ void StatOutput(u64 *stat) {
name[StatInt_tcgetattr] = " tcgetattr ";
name[StatInt_realpath] = " realpath ";
name[StatInt_canonicalize_file_name] = " canonicalize_file_name ";
+ name[StatInt_confstr] = " confstr ";
name[StatAnnotation] = "Dynamic annotations ";
name[StatAnnotateHappensBefore] = " HappensBefore ";
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h
index 6131721537a..606ee66e759 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h
@@ -347,6 +347,7 @@ enum StatType {
StatInt_tcgetattr,
StatInt_realpath,
StatInt_canonicalize_file_name,
+ StatInt_confstr,
// Dynamic annotations.
StatAnnotation,
OpenPOWER on IntegriCloud