Skip to content

Commit 416c48e

Browse files
luhenryPaul Hohensee
authored and
Paul Hohensee
committed
8310265: (process) jspawnhelper should not use argv[0]
Backport-of: cd6cb730c934d8e16d4bd8e3342e59e806f158f9
1 parent 34cc089 commit 416c48e

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
@@ -134,10 +134,10 @@ int main(int argc, char *argv[]) {
134134
ChildStuff c;
135135
int t;
136136
struct stat buf;
137-
/* argv[0] contains the fd number to read all the child info */
137+
/* argv[1] contains the fd number to read all the child info */
138138
int r, fdin, fdout;
139139

140-
r = sscanf (argv[argc-1], "%d:%d", &fdin, &fdout);
140+
r = sscanf (argv[1], "%d:%d", &fdin, &fdout);
141141
if (r == 2 && fcntl(fdin, F_GETFD) != -1) {
142142
fstat(fdin, &buf);
143143
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
@@ -394,16 +394,20 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
394394
jboolean isCopy;
395395
int i, offset, rval, bufsize, magic;
396396
char *buf, buf1[16];
397-
char *hlpargs[2];
397+
char *hlpargs[3];
398398
SpawnInfo sp;
399399

400400
/* need to tell helper which fd is for receiving the childstuff
401401
* and which fd to send response back on
402402
*/
403403
snprintf(buf1, sizeof(buf1), "%d:%d", c->childenv[0], c->fail[1]);
404-
/* put the fd string as argument to the helper cmd */
405-
hlpargs[0] = buf1;
406-
hlpargs[1] = 0;
404+
/* NULL-terminated argv array.
405+
* argv[0] contains path to jspawnhelper, to follow conventions.
406+
* argv[1] contains the fd string as argument to jspawnhelper
407+
*/
408+
hlpargs[0] = (char*)helperpath;
409+
hlpargs[1] = buf1;
410+
hlpargs[2] = NULL;
407411

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

0 commit comments

Comments
 (0)