diff --git a/linker/linker.cpp b/linker/linker.cpp index 0fdf90d2e..c1938612e 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -2365,12 +2365,16 @@ int do_dlclose(void* handle) { } bool init_namespaces(const char* public_ns_sonames, const char* anon_ns_library_path) { - CHECK(public_ns_sonames != nullptr); if (g_public_namespace_initialized) { DL_ERR("public namespace has already been initialized."); return false; } + if (public_ns_sonames == nullptr || public_ns_sonames[0] == '\0') { + DL_ERR("error initializing public namespace: the list of public libraries is empty."); + return false; + } + std::vector sonames = android::base::Split(public_ns_sonames, ":"); ProtectedDataGuard guard; diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp index 87e5dbc09..420c93455 100644 --- a/tests/dlext_test.cpp +++ b/tests/dlext_test.cpp @@ -629,6 +629,10 @@ TEST(dlext, ns_smoke) { ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: " "\"libnstest_public.so\" was not found in the default namespace", dlerror()); + ASSERT_FALSE(android_init_namespaces("", nullptr)); + ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: " + "the list of public libraries is empty.", dlerror()); + const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH; const std::string lib_public_path = lib_path + "/public_namespace_libs/" + g_public_lib;