From ecbf64648fc164efce0570579a781d341369fc95 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Fri, 22 Mar 2013 11:59:49 +0000 Subject: [PATCH] [msan] Handle dlopen() failure in dlopen interceptor. llvm-svn: 177728 --- compiler-rt/lib/msan/msan_interceptors.cc | 2 +- compiler-rt/lib/msan/tests/msan_test.cc | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc index 677b8a8f9df9..958e19d215a8 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cc +++ b/compiler-rt/lib/msan/msan_interceptors.cc @@ -807,7 +807,7 @@ INTERCEPTOR(void *, dlopen, const char *filename, int flag) { EnterLoader(); link_map *map = (link_map *)REAL(dlopen)(filename, flag); ExitLoader(); - if (!__msan_has_dynamic_component()) { + if (!__msan_has_dynamic_component() && map) { // If msandr didn't clear the shadow before the initializers ran, we do it // ourselves afterwards. UnpoisonMappedDSO(map); diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc index 2120f0efa30d..60d4fd526e19 100644 --- a/compiler-rt/lib/msan/tests/msan_test.cc +++ b/compiler-rt/lib/msan/tests/msan_test.cc @@ -1397,6 +1397,13 @@ TEST(MemorySanitizer, dlopen) { delete[] path; } + +// Regression test for a crash in dlopen() interceptor. +TEST(MemorySanitizer, dlopenFailed) { + const char *path = "/libmsan_loadable_does_not_exist.x86_64.so"; + void *lib = dlopen(path, RTLD_LAZY); + ASSERT_EQ(0, lib); +} } // namespace TEST(MemorySanitizer, scanf) {