summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-31 16:58:44 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-31 16:58:44 +0000
commitae7db43b4e8341c0f1c3166ffcf2b7c2aa7391f7 (patch)
tree7b14c4246a60a8b51fe174df93a9185a14aecbb0
parent2bcd3b547e8de0d152aa41366defb83f3fe766b8 (diff)
downloadcompiler-rt-ae7db43b4e8341c0f1c3166ffcf2b7c2aa7391f7.tar.gz
compiler-rt-ae7db43b4e8341c0f1c3166ffcf2b7c2aa7391f7.tar.bz2
compiler-rt-ae7db43b4e8341c0f1c3166ffcf2b7c2aa7391f7.tar.xz
[msan] Intercept dlerror.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193760 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/msan/lit_tests/dlerror.cc14
-rw-r--r--lib/msan/msan_interceptors.cc8
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/msan/lit_tests/dlerror.cc b/lib/msan/lit_tests/dlerror.cc
new file mode 100644
index 00000000..281b3164
--- /dev/null
+++ b/lib/msan/lit_tests/dlerror.cc
@@ -0,0 +1,14 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t
+
+#include <assert.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+ void *p = dlopen("/bad/file/name", RTLD_NOW);
+ assert(!p);
+ char *s = dlerror();
+ printf("%s, %zu\n", s, strlen(s));
+ return 0;
+}
diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc
index 8c867c3b..b96e4b3f 100644
--- a/lib/msan/msan_interceptors.cc
+++ b/lib/msan/msan_interceptors.cc
@@ -896,6 +896,13 @@ INTERCEPTOR(int, dladdr, void *addr, dlinfo *info) {
return res;
}
+INTERCEPTOR(char *, dlerror) {
+ ENSURE_MSAN_INITED();
+ char *res = REAL(dlerror)();
+ if (res != 0) __msan_unpoison(res, REAL(strlen)(res) + 1);
+ return res;
+}
+
// dlopen() ultimately calls mmap() down inside the loader, which generally
// doesn't participate in dynamic symbol resolution. Therefore we won't
// intercept its calls to mmap, and we have to hook it here. The loader
@@ -1497,6 +1504,7 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(recv);
INTERCEPT_FUNCTION(recvfrom);
INTERCEPT_FUNCTION(dladdr);
+ INTERCEPT_FUNCTION(dlerror);
INTERCEPT_FUNCTION(dlopen);
INTERCEPT_FUNCTION(dl_iterate_phdr);
INTERCEPT_FUNCTION(getrusage);