diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index 91dfc6023e4200ed2c9e759d3685ea675d0d136f..55100a5347fd8cb06ea3dea025a2b74189824364 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -282,6 +282,11 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin void android_os_Process_setProcessFrozen( JNIEnv *env, jobject clazz, jint pid, jint uid, jboolean freeze) { + if (uid < 0) { + jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "uid is negative: %d", uid); + return; + } + bool success = true; if (freeze) { @@ -305,6 +310,11 @@ jint android_os_Process_getProcessGroup(JNIEnv* env, jobject clazz, jint pid) } jint android_os_Process_createProcessGroup(JNIEnv* env, jobject clazz, jint uid, jint pid) { + if (uid < 0) { + return jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", + "uid is negative: %d", uid); + } + return createProcessGroup(uid, pid); } @@ -590,12 +600,21 @@ void android_os_Process_setArgV0(JNIEnv* env, jobject clazz, jstring name) jint android_os_Process_setUid(JNIEnv* env, jobject clazz, jint uid) { + if (uid < 0) { + return jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", + "uid is negative: %d", uid); + } + return setuid(uid) == 0 ? 0 : errno; } -jint android_os_Process_setGid(JNIEnv* env, jobject clazz, jint uid) -{ - return setgid(uid) == 0 ? 0 : errno; +jint android_os_Process_setGid(JNIEnv* env, jobject clazz, jint gid) { + if (gid < 0) { + return jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", + "gid is negative: %d", gid); + } + + return setgid(gid) == 0 ? 0 : errno; } static int pid_compare(const void* v1, const void* v2) @@ -1235,11 +1254,21 @@ jintArray android_os_Process_getPidsForCommands(JNIEnv* env, jobject clazz, jint android_os_Process_killProcessGroup(JNIEnv* env, jobject clazz, jint uid, jint pid) { + if (uid < 0) { + return jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", + "uid is negative: %d", uid); + } + return killProcessGroup(uid, pid, SIGKILL); } jint android_os_Process_sendSignalToProcessGroup(JNIEnv* env, jobject clazz, jint uid, jint pid, jint signal) { + if (uid < 0) { + return jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", + "uid is negative: %d", uid); + } + return sendSignalToProcessGroup(uid, pid, signal); } @@ -1258,6 +1287,11 @@ static jint android_os_Process_nativePidFdOpen(JNIEnv* env, jobject, jint pid, j } void android_os_Process_freezeCgroupUID(JNIEnv* env, jobject clazz, jint uid, jboolean freeze) { + if (uid < 0) { + jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "uid is negative: %d", uid); + return; + } + bool success = true; if (freeze) {