Skip to content

Commit 47d00a4

Browse files
committed
8310265: (process) jspawnhelper should not use argv[0]
Reviewed-by: simonis, rriggs
1 parent e022e87 commit 47d00a4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/java.base/unix/native/jspawnhelper/jspawnhelper.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ void initChildStuff (int fdin, int fdout, ChildStuff *c) {
136136
int main(int argc, char *argv[]) {
137137
ChildStuff c;
138138
struct stat buf;
139-
/* argv[0] contains the fd number to read all the child info */
139+
/* argv[1] contains the fd number to read all the child info */
140140
int r, fdinr, fdinw, fdout;
141141
sigset_t unblock_signals;
142142

143143
#ifdef DEBUG
144144
jtregSimulateCrash(0, 4);
145145
#endif
146-
r = sscanf (argv[argc-1], "%d:%d:%d", &fdinr, &fdinw, &fdout);
146+
r = sscanf (argv[1], "%d:%d:%d", &fdinr, &fdinw, &fdout);
147147
if (r == 3 && fcntl(fdinr, F_GETFD) != -1 && fcntl(fdinw, F_GETFD) != -1) {
148148
fstat(fdinr, &buf);
149149
if (!S_ISFIFO(buf.st_mode))

src/java.base/unix/native/libjava/ProcessImpl_md.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -488,16 +488,20 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
488488
pid_t resultPid;
489489
int i, offset, rval, bufsize, magic;
490490
char *buf, buf1[(3 * 11) + 3]; // "%d:%d:%d\0"
491-
char *hlpargs[2];
491+
char *hlpargs[3];
492492
SpawnInfo sp;
493493

494494
/* need to tell helper which fd is for receiving the childstuff
495495
* and which fd to send response back on
496496
*/
497497
snprintf(buf1, sizeof(buf1), "%d:%d:%d", c->childenv[0], c->childenv[1], c->fail[1]);
498-
/* put the fd string as argument to the helper cmd */
499-
hlpargs[0] = buf1;
500-
hlpargs[1] = 0;
498+
/* NULL-terminated argv array.
499+
* argv[0] contains path to jspawnhelper, to follow conventions.
500+
* argv[1] contains the fd string as argument to jspawnhelper
501+
*/
502+
hlpargs[0] = (char*)helperpath;
503+
hlpargs[1] = buf1;
504+
hlpargs[2] = NULL;
501505

502506
/* Following items are sent down the pipe to the helper
503507
* after it is spawned.

0 commit comments

Comments
 (0)