linker namespace name is duped when the namespace is created
A linker namespace lives longer than its caller. It is never deleted
once created in a process. Currently, the pointer to the name is simply
copied which results dangling reference when the name is actually from
temporary objects like std::object. Fixing the issue by strdup'ing the
name upon namespace creation.
Bug: 130388701
Test: atest CtsJniTestCases; the log does not show broken error messages
like
unexpected dlerror: dlopen failed: library "/system/lib64/android.frameworks.cameraservice.common@2.0.so" needed or dlopened by "/data/app/android.jni.cts-HP6GyGXYy5honHQAffUXgw==/lib/arm64/libjnitest.so" is not accessible for the namespace " mT?"
Change-Id: I25d9d76f8520f490755c189ded5659e6c9741f79
diff --git a/linker/linker_namespaces.h b/linker/linker_namespaces.h
index f4428eb..215ad05 100644
--- a/linker/linker_namespaces.h
+++ b/linker/linker_namespaces.h
@@ -72,9 +72,9 @@
struct android_namespace_t {
public:
- android_namespace_t() : name_(nullptr), is_isolated_(false), is_greylist_enabled_(false) {}
+ android_namespace_t() : is_isolated_(false), is_greylist_enabled_(false) {}
- const char* get_name() const { return name_; }
+ const char* get_name() const { return name_.c_str(); }
void set_name(const char* name) { name_ = name; }
bool is_isolated() const { return is_isolated_; }
@@ -161,7 +161,7 @@
soinfo_list_t get_shared_group();
private:
- const char* name_;
+ std::string name_;
bool is_isolated_;
bool is_greylist_enabled_;
std::vector<std::string> ld_library_paths_;