From 7cd95c54b90efe3a9b0b2c2e0a7c6c5e7e03acda Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Tue, 18 Feb 2025 20:32:48 +0100 Subject: [PATCH] Move `putenv` out of the if block It turns out that, if we call `putenv` inside the if block, then it is no longer valid out of the block. --- dex2oat/src/main/cpp/dex2oat.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dex2oat/src/main/cpp/dex2oat.c b/dex2oat/src/main/cpp/dex2oat.c index 7a8b0f44d..a3e4863d3 100644 --- a/dex2oat/src/main/cpp/dex2oat.c +++ b/dex2oat/src/main/cpp/dex2oat.c @@ -117,6 +117,9 @@ int main(int argc, char **argv) { read_int(sock_fd); close(sock_fd); + if (hooker_fd == -1) { + PLOGE("failed to read liboat_hook.so"); + } LOGD("sock: %s %d", sock.sun_path + 1, stock_fd); const char *new_argv[argc + 2]; @@ -131,15 +134,12 @@ int main(int argc, char **argv) { putenv((char *)libenv); } - if (hooker_fd > 0) { - // Set LD_PRELOAD to load liboat_hook.so - const int STRING_BUFFER = 50; - char env_str[STRING_BUFFER]; - snprintf(env_str, STRING_BUFFER, "LD_PRELOAD=/proc/%d/fd/%d", getpid(), hooker_fd); - putenv(env_str); - } else { - LOGE("Unable to read liboat_hook.so"); - } + // Set LD_PRELOAD to load liboat_hook.so + const int STRING_BUFFER = 50; + char env_str[STRING_BUFFER]; + snprintf(env_str, STRING_BUFFER, "LD_PRELOAD=/proc/%d/fd/%d", getpid(), hooker_fd); + putenv(env_str); + LOGD("Set env %s", env_str); fexecve(stock_fd, (char **)new_argv, environ);