[compiler-rt] r187575 - [msan] Intercept setenv, putenv.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu Aug 1 04:14:15 PDT 2013
Author: eugenis
Date: Thu Aug 1 06:14:14 2013
New Revision: 187575
URL: http://llvm.org/viewvc/llvm-project?rev=187575&view=rev
Log:
[msan] Intercept setenv, putenv.
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/msan/tests/msan_test.cc
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=187575&r1=187574&r2=187575&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Aug 1 06:14:14 2013
@@ -529,6 +529,32 @@ INTERCEPTOR(char *, getenv, char *name)
return res;
}
+extern char **environ;
+
+static void UnpoisonEnviron() {
+ char **envp = environ;
+ for (; *envp; ++envp) {
+ __msan_unpoison(envp, sizeof(*envp));
+ __msan_unpoison(*envp, REAL(strlen)(*envp) + 1);
+ }
+ // Trailing NULL pointer.
+ __msan_unpoison(envp, sizeof(*envp));
+}
+
+INTERCEPTOR(int, setenv, const char *name, const char *value, int overwrite) {
+ ENSURE_MSAN_INITED();
+ int res = REAL(setenv)(name, value, overwrite);
+ if (!res) UnpoisonEnviron();
+ return res;
+}
+
+INTERCEPTOR(int, putenv, char *string) {
+ ENSURE_MSAN_INITED();
+ int res = REAL(putenv)(string);
+ if (!res) UnpoisonEnviron();
+ return res;
+}
+
INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) {
ENSURE_MSAN_INITED();
int res = REAL(__fxstat)(magic, fd, buf);
@@ -1198,6 +1224,8 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(wcscmp);
INTERCEPT_FUNCTION(wcstod);
INTERCEPT_FUNCTION(getenv);
+ INTERCEPT_FUNCTION(setenv);
+ INTERCEPT_FUNCTION(putenv);
INTERCEPT_FUNCTION(gettimeofday);
INTERCEPT_FUNCTION(fcvt);
INTERCEPT_FUNCTION(__fxstat);
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=187575&r1=187574&r2=187575&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu Aug 1 06:14:14 2013
@@ -986,6 +986,25 @@ TEST(MemorySanitizer, canonicalize_file_
free(res);
}
+extern char **environ;
+
+TEST(MemorySanitizer, setenv) {
+ setenv("AAA", "BBB", 1);
+ for (char **envp = environ; *envp; ++envp) {
+ EXPECT_NOT_POISONED(*envp);
+ EXPECT_NOT_POISONED(*envp[0]);
+ }
+}
+
+TEST(MemorySanitizer, putenv) {
+ char s[] = "AAA=BBB";
+ putenv(s);
+ for (char **envp = environ; *envp; ++envp) {
+ EXPECT_NOT_POISONED(*envp);
+ EXPECT_NOT_POISONED(*envp[0]);
+ }
+}
+
TEST(MemorySanitizer, memcpy) {
char* x = new char[2];
char* y = new char[2];
More information about the llvm-commits
mailing list