Skip to content

Commit

Permalink
8310265: (process) jspawnhelper should not use argv[0]
Browse files Browse the repository at this point in the history
Reviewed-by: stuefe
Backport-of: 47d00a4cbeff5d757dda9c660dfd2385c02a57d7
  • Loading branch information
luhenry authored and tstuefe committed Nov 6, 2023
1 parent d4ed7c2 commit cd6cb73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/java.base/unix/native/jspawnhelper/jspawnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ int main(int argc, char *argv[]) {
ChildStuff c;
int t;
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, fdin, fdout;

r = sscanf (argv[argc-1], "%d:%d", &fdin, &fdout);
r = sscanf (argv[1], "%d:%d", &fdin, &fdout);
if (r == 2 && fcntl(fdin, F_GETFD) != -1) {
fstat(fdin, &buf);
if (!S_ISFIFO(buf.st_mode))
Expand Down
12 changes: 8 additions & 4 deletions src/java.base/unix/native/libjava/ProcessImpl_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,16 +491,20 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
jboolean isCopy;
int i, offset, rval, bufsize, magic;
char *buf, buf1[16];
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", c->childenv[0], 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.
Expand Down

1 comment on commit cd6cb73

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.