Skip to content

Commit cd6cb73

Browse files
luhenrytstuefe
authored andcommitted
8310265: (process) jspawnhelper should not use argv[0]
Reviewed-by: stuefe Backport-of: 47d00a4cbeff5d757dda9c660dfd2385c02a57d7
1 parent d4ed7c2 commit cd6cb73

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
@@ -491,16 +491,20 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
491491
jboolean isCopy;
492492
int i, offset, rval, bufsize, magic;
493493
char *buf, buf1[16];
494-
char *hlpargs[2];
494+
char *hlpargs[3];
495495
SpawnInfo sp;
496496

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

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

0 commit comments

Comments
 (0)