[msan] Intercept dlerror.

llvm-svn: 193760
This commit is contained in:
Evgeniy Stepanov 2013-10-31 16:58:44 +00:00
parent d41dbadacd
commit 13322c6eda
2 changed files with 22 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);