From 2828cdc7ca40e8c142338b36c146968076eca33e Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Fri, 25 Oct 2024 00:36:31 +0000 Subject: Fix system_server SIGABRT due to non-UTF-8 process name in /proc/PID/stat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is possible for process names to include non-printable characters. When that is the case, the second column (comm) of /proc/PID/stat output includes '�' characters which are fed directly into NewStringUTF. NewStringUTF detects the non-UTF-8 characters and aborts. Fix this by replacing all non-printable characters with question marks '?' before calling NewStringUTF. Bug: 351917521 Bug: 361017804 Test: adb wait-for-device shell 'echo -ne "\x9C\x88foo" > /proc/$$/comm; sleep 9999' Change-Id: I040c8640e441c4545747edb5870a746892d1b09c --- core/jni/android_util_Process.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index 4cc904153aac..4369cb0d82b4 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -1004,6 +1005,8 @@ jboolean android_os_Process_parseProcLineArray(JNIEnv* env, jobject clazz, } } if ((mode&PROC_OUT_STRING) != 0 && di < NS) { + std::replace_if(buffer+start, buffer+end, + [](unsigned char c){ return !std::isprint(c); }, '?'); jstring str = env->NewStringUTF(buffer+start); env->SetObjectArrayElement(outStrings, di, str); } -- cgit v1.2.3-59-g8ed1b