From 43240a6a7dc33d6329072960f380a0f0f2242b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Rodr=C3=ADguez?= Date: Mon, 13 Jul 2026 17:16:47 +0200 Subject: [PATCH] Avoid closing unrelated descriptors when spawning fails early MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VMProcess.nativeSpawn() can fail before calling cpproc_forkAndExec() (null/empty command array, string extraction failure, malloc failure). Since fds[] is not initialized, the cleanup path could end up closing up to three arbitrary live descriptors. Initialize every descriptor to -1 at declaration so all early failure paths are safe. Signed-off-by: Guillermo Rodríguez --- native/jni/java-lang/java_lang_VMProcess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/jni/java-lang/java_lang_VMProcess.c b/native/jni/java-lang/java_lang_VMProcess.c index 3f358ce48..9ef2d97a0 100644 --- a/native/jni/java-lang/java_lang_VMProcess.c +++ b/native/jni/java-lang/java_lang_VMProcess.c @@ -126,7 +126,7 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, jobjectArray envArray, jobject dirFile, jboolean redirect) { - int fds[CPIO_EXEC_NUM_PIPES]; + int fds[CPIO_EXEC_NUM_PIPES] = { -1, -1, -1 }; jobject streams[CPIO_EXEC_NUM_PIPES] = { NULL, NULL, NULL }; jobject dirString = NULL; char **newEnviron = NULL;