# HG changeset patch # User stuefe # Date 1559653517 -7200 # Tue Jun 04 15:05:17 2019 +0200 # Node ID 7a2b7ec03f0e3a02352f47401a282903659754d1 # Parent 8b8d83cf9097fd97b359d7a19583e81d822eebcd [mq]: 8224181-On-child-process-spawn--child-may-write-to-wrong-file-descriptor-instead-of-the-fail-pipe diff -r 8b8d83cf9097 -r 7a2b7ec03f0e src/java.base/unix/native/libjava/childproc.c --- a/src/java.base/unix/native/libjava/childproc.c Tue Jun 04 13:34:50 2019 +0530 +++ b/src/java.base/unix/native/libjava/childproc.c Tue Jun 04 15:05:17 2019 +0200 @@ -313,6 +313,7 @@ childProcess(void *arg) { const ChildStuff* p = (const ChildStuff*) arg; + int fail_pipe_fd = p->fail[1]; /* Close the parent sides of the pipes. Closing pipe fds here is redundant, since closeDescriptors() @@ -343,9 +344,12 @@ goto WhyCantJohnnyExec; } - if (moveDescriptor(p->fail[1], FAIL_FILENO) == -1) + if (moveDescriptor(fail_pipe_fd, FAIL_FILENO) == -1) goto WhyCantJohnnyExec; + /* We moved the fail pipe fd */ + fail_pipe_fd = FAIL_FILENO; + /* close everything */ if (closeDescriptors() == 0) { /* failed, close the old way */ int max_fd = (int)sysconf(_SC_OPEN_MAX); @@ -377,7 +381,7 @@ */ { int errnum = errno; - restartableWrite(FAIL_FILENO, &errnum, sizeof(errnum)); + restartableWrite(fail_pipe_fd, &errnum, sizeof(errnum)); } close(FAIL_FILENO); _exit(-1);