diff --git a/src/java.base/unix/native/jspawnhelper/jspawnhelper.c b/src/java.base/unix/native/jspawnhelper/jspawnhelper.c index 16845901589..5a583fda61f 100644 --- a/src/java.base/unix/native/jspawnhelper/jspawnhelper.c +++ b/src/java.base/unix/native/jspawnhelper/jspawnhelper.c @@ -136,14 +136,14 @@ void initChildStuff (int fdin, int fdout, ChildStuff *c) { int main(int argc, char *argv[]) { ChildStuff c; struct stat buf; - /* argv[0] contains the fd number to read all the child info */ + /* argv[1] contains the fd number to read all the child info */ int r, fdinr, fdinw, fdout; sigset_t unblock_signals; #ifdef DEBUG jtregSimulateCrash(0, 4); #endif - r = sscanf (argv[argc-1], "%d:%d:%d", &fdinr, &fdinw, &fdout); + r = sscanf (argv[1], "%d:%d:%d", &fdinr, &fdinw, &fdout); if (r == 3 && fcntl(fdinr, F_GETFD) != -1 && fcntl(fdinw, F_GETFD) != -1) { fstat(fdinr, &buf); if (!S_ISFIFO(buf.st_mode)) diff --git a/src/java.base/unix/native/libjava/ProcessImpl_md.c b/src/java.base/unix/native/libjava/ProcessImpl_md.c index 66c44956b21..04a1e5cf6b5 100644 --- a/src/java.base/unix/native/libjava/ProcessImpl_md.c +++ b/src/java.base/unix/native/libjava/ProcessImpl_md.c @@ -488,16 +488,20 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath) pid_t resultPid; int i, offset, rval, bufsize, magic; char *buf, buf1[(3 * 11) + 3]; // "%d:%d:%d\0" - char *hlpargs[2]; + char *hlpargs[3]; SpawnInfo sp; /* need to tell helper which fd is for receiving the childstuff * and which fd to send response back on */ snprintf(buf1, sizeof(buf1), "%d:%d:%d", c->childenv[0], c->childenv[1], c->fail[1]); - /* put the fd string as argument to the helper cmd */ - hlpargs[0] = buf1; - hlpargs[1] = 0; + /* NULL-terminated argv array. + * argv[0] contains path to jspawnhelper, to follow conventions. + * argv[1] contains the fd string as argument to jspawnhelper + */ + hlpargs[0] = (char*)helperpath; + hlpargs[1] = buf1; + hlpargs[2] = NULL; /* Following items are sent down the pipe to the helper * after it is spawned.