From cf589f8c64cf95affbd14adaa69026eefa41599e Mon Sep 17 00:00:00 2001 From: Shaka Huang Date: Sat, 1 Feb 2020 14:36:34 +0800 Subject: [PATCH] Fix error loading libsqlite.so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vendors are always adding “extra libraries” in /vendor/lib* for their own sake, in this case AS*S loaded with customized `libicuuc.so` for Zenf*ne 5z and led to the failure of dynamic loading libsqlite.so: db: dlopen failed: cannot locate symbol "UCNV_FROM_U_CALLBACK_ESCAPE_63" referenced by "/apex/com.android.runtime/lib64/libandroidicu.so"... Signed-off-by: Shaka Huang * Minor optimizations Co-authored-by: John Wu --- native/jni/core/db.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/native/jni/core/db.cpp b/native/jni/core/db.cpp index 3ba9c790b..f4d1955ca 100644 --- a/native/jni/core/db.cpp +++ b/native/jni/core/db.cpp @@ -57,9 +57,9 @@ static void (*android_update_LD_LIBRARY_PATH)(const char *ld_library_path); } #ifdef __LP64__ -constexpr char apex_path[] = ":/apex/com.android.runtime/lib64"; +constexpr char apex_path[] = "/apex/com.android.runtime/lib64:"; #else -constexpr char apex_path[] = ":/apex/com.android.runtime/lib"; +constexpr char apex_path[] = "/apex/com.android.runtime/lib:"; #endif static int dl_init = 0; @@ -80,15 +80,14 @@ static bool dload_sqlite() { // Inject APEX into LD_LIBRARY_PATH char ld_path[4096]; - android_get_LD_LIBRARY_PATH(ld_path, sizeof(ld_path)); - int len = strlen(ld_path); - strcpy(ld_path + len, apex_path); + memcpy(ld_path, apex_path, sizeof(apex_path)); + constexpr int len = sizeof(apex_path) - 1; + android_get_LD_LIBRARY_PATH(ld_path + len, sizeof(ld_path) - len); android_update_LD_LIBRARY_PATH(ld_path); sqlite = dlopen("libsqlite.so", RTLD_LAZY); // Revert LD_LIBRARY_PATH just in case - ld_path[len] = '\0'; - android_update_LD_LIBRARY_PATH(ld_path); + android_update_LD_LIBRARY_PATH(ld_path + len); } DLERR(sqlite);