From 0c3f120fc67a3cea8d706ea5cfeef85f6c8ad2bc Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Fri, 26 Apr 2019 08:51:50 -0700 Subject: [PATCH] Nativeloader: Restrict anonymous namespace creation Create the anonymous namespace only from a non-empty library path. This is a better heuristic than the current "first-come" one. It allows creating classloaders that are not directly related to an app's "main" classloader, that is, do not have any library path. This is the case, for example, for shared libraries, including preloaded ones. Longer-term, the anonymous namespace creation should be made explicit, so that the framework can have full control. (cherry picked from commit b9df7d936c7dfd1741b56e722065a46ac1e50607) Bug: 130623656 Test: m Test: manual Merged-In: I8251363b372e365d10ae09d23df93d76388ac7f9 Change-Id: I8251363b372e365d10ae09d23df93d76388ac7f9 --- libnativeloader/native_loader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index 5cc0857f6..e460b1a30 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -220,7 +220,9 @@ class LibraryNamespaces { } } - if (!initialized_ && !InitPublicNamespace(library_path.c_str(), error_msg)) { + // Initialize the anonymous namespace with the first non-empty library path. + if (!library_path.empty() && !initialized_ && + !InitPublicNamespace(library_path.c_str(), error_msg)) { return nullptr; }