diff options
author | Dimitry Ivanov <dimitry@google.com> | 2017-10-24 06:52:25 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-10-24 06:52:25 +0000 |
commit | 640fda69bf510878677aa84d6e4246cf48fd1c0c (patch) | |
tree | 5911601885ce84c9366700b77ea9acec5feb7dc1 /tests/dlext_test.cpp | |
parent | b0b34d51351d1fe1c8789609d679529fa834aa41 (diff) | |
parent | 0b1c8be3be5983e5ae3dfe4aa864675298b5455b (diff) |
Merge "linker: fix error message for inaccessible libs"
am: 0b1c8be3be
Change-Id: I1dc1c1ec8aa104f6b2efd9c6ce5c2188398a7161
Diffstat (limited to 'tests/dlext_test.cpp')
-rw-r--r-- | tests/dlext_test.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp index 7028ca77e..3f6da59ca 100644 --- a/tests/dlext_test.cpp +++ b/tests/dlext_test.cpp @@ -1589,6 +1589,54 @@ TEST(dlext, ns_isolated_rtld_global) { ASSERT_STREQ("dlopen failed: library \"libnstest_public.so\" not found", dlerror()); } +TEST(dlext, ns_inaccessible_error_message) { + // We set up 2 namespaces (a and b) and link a->b with a shared library + // libtestshared.so. Then try to dlopen different library with the same + // name from in namespace a. Note that library should not be accessible + // in either namespace but since it's soname is in the list of shared libs + // the linker will attempt to find it in linked namespace. + // + // Check the error message and make sure it mentions correct namespace name. + ASSERT_TRUE(android_init_anonymous_namespace(g_core_shared_libs.c_str(), nullptr)); + + android_namespace_t* ns_a = + android_create_namespace("ns_a", + nullptr, + (get_testlib_root() + "/private_namespace_libs").c_str(), + ANDROID_NAMESPACE_TYPE_ISOLATED, + nullptr, + nullptr); + ASSERT_TRUE(ns_a != nullptr) << dlerror(); + ASSERT_TRUE(android_link_namespaces(ns_a, nullptr, g_core_shared_libs.c_str())) << dlerror(); + + android_namespace_t* ns_b = + android_create_namespace("ns_b", + nullptr, + get_testlib_root().c_str(), + ANDROID_NAMESPACE_TYPE_ISOLATED, + nullptr, + nullptr); + ASSERT_TRUE(ns_b != nullptr) << dlerror(); + ASSERT_TRUE(android_link_namespaces(ns_b, nullptr, g_core_shared_libs.c_str())) << dlerror(); + + ASSERT_TRUE(android_link_namespaces(ns_a, ns_b, "libtestshared.so")) << dlerror(); + + android_dlextinfo extinfo; + extinfo.flags = ANDROID_DLEXT_USE_NAMESPACE; + extinfo.library_namespace = ns_a; + + std::string library_path = get_testlib_root() + "/inaccessible_libs/libtestshared.so"; + + void* handle = android_dlopen_ext(library_path.c_str(), RTLD_NOW, &extinfo); + ASSERT_TRUE(handle == nullptr); + std::string expected_dlerror = + android::base::StringPrintf("dlopen failed: library \"%s\" needed or dlopened by \"%s\"" + " is not accessible for the namespace \"ns_a\"", + library_path.c_str(), + get_executable_path().c_str()); + ASSERT_EQ(expected_dlerror, dlerror()); +} + TEST(dlext, ns_anonymous) { static const char* root_lib = "libnstest_root.so"; std::string shared_libs = g_core_shared_libs + ":" + g_public_lib; |