From 94cc1b3972dd71476c559637626091f2fa7bbb5f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 17 Apr 2020 13:11:00 -0700 Subject: [PATCH] Tell bionic when we overwrite argv[0]. Otherwise bionic might still have a pointer into the old content. (Cherrypick of 07ce3ccc80c26105f2ccfc8c255353274d8b5861.) Bug: https://issuetracker.google.com/152893281 Test: treehugger Merged-In: I25e31c5da33e529c750ef6f2e3f36ca62cf4d231 Change-Id: I25e31c5da33e529c750ef6f2e3f36ca62cf4d231 --- core/jni/AndroidRuntime.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index b51d4f509f384..4cb2e975a58b0 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -301,6 +301,8 @@ AndroidRuntime::~AndroidRuntime() } void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) { + // Set the kernel's task name, for as much of the name as we can fit. + // The kernel's TASK_COMM_LEN minus one for the terminating NUL == 15. if (setProcName) { int len = strlen(argv0); if (len < 15) { @@ -309,8 +311,14 @@ void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) { pthread_setname_np(pthread_self(), argv0 + len - 15); } } + + // Directly change the memory pointed to by argv[0]. memset(mArgBlockStart, 0, mArgBlockLength); strlcpy(mArgBlockStart, argv0, mArgBlockLength); + + // Let bionic know that we just did that, because __progname points + // into argv[0] (https://issuetracker.google.com/152893281). + setprogname(mArgBlockStart); } status_t AndroidRuntime::callMain(const String8& className, jclass clazz,