loader: asan path translation now works for symlinks

Bionic Loader now resolves real path for a library before running
asan path-translation. This fixes situations for bundled loading
libraries which are effectively symlinks to system library;
for example:

 $ adb shell ls -l /system/app/NfcNci/lib/arm64/libnfc_nci_jni.so
 /system/app/NfcNci/lib/arm64/libnfc_nci_jni.so -> /system/lib64/libnfc_nci_jni.so

Bug: http://b/33278445
Test: make and boot
Change-Id: If14a12087c92f8ca628504556332ba0cb67c9118
This commit is contained in:
Dimitry Ivanov 2016-12-05 13:35:47 -08:00
parent f8b4ff4aa1
commit 6c14f86309

View file

@ -1785,18 +1785,21 @@ void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo,
std::string asan_name_holder;
const char* translated_name = name;
if (g_is_asan) {
if (file_is_in_dir(name, kSystemLibDir)) {
asan_name_holder = std::string(kAsanSystemLibDir) + "/" + basename(name);
if (file_exists(asan_name_holder.c_str())) {
translated_name = asan_name_holder.c_str();
PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
}
} else if (file_is_in_dir(name, kVendorLibDir)) {
asan_name_holder = std::string(kAsanVendorLibDir) + "/" + basename(name);
if (file_exists(asan_name_holder.c_str())) {
translated_name = asan_name_holder.c_str();
PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
if (g_is_asan && translated_name != nullptr && translated_name[0] == '/') {
char translated_path[PATH_MAX];
if (realpath(translated_name, translated_path) != nullptr) {
if (file_is_in_dir(translated_path, kSystemLibDir)) {
asan_name_holder = std::string(kAsanSystemLibDir) + "/" + basename(translated_path);
if (file_exists(asan_name_holder.c_str())) {
translated_name = asan_name_holder.c_str();
PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
}
} else if (file_is_in_dir(translated_path, kVendorLibDir)) {
asan_name_holder = std::string(kAsanVendorLibDir) + "/" + basename(translated_path);
if (file_exists(asan_name_holder.c_str())) {
translated_name = asan_name_holder.c_str();
PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
}
}
}
}