8310265: (process) jspawnhelper should not use argv[0]

Reviewed-by: simonis, rriggs
This commit is contained in:
Thomas Stuefe 2023-06-21 04:55:43 +00:00
parent e022e87654
commit 47d00a4cbe
2 changed files with 10 additions and 6 deletions

View File

@ -136,14 +136,14 @@ void initChildStuff (int fdin, int fdout, ChildStuff *c) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
ChildStuff c; ChildStuff c;
struct stat buf; 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; int r, fdinr, fdinw, fdout;
sigset_t unblock_signals; sigset_t unblock_signals;
#ifdef DEBUG #ifdef DEBUG
jtregSimulateCrash(0, 4); jtregSimulateCrash(0, 4);
#endif #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) { if (r == 3 && fcntl(fdinr, F_GETFD) != -1 && fcntl(fdinw, F_GETFD) != -1) {
fstat(fdinr, &buf); fstat(fdinr, &buf);
if (!S_ISFIFO(buf.st_mode)) if (!S_ISFIFO(buf.st_mode))

View File

@ -488,16 +488,20 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
pid_t resultPid; pid_t resultPid;
int i, offset, rval, bufsize, magic; int i, offset, rval, bufsize, magic;
char *buf, buf1[(3 * 11) + 3]; // "%d:%d:%d\0" char *buf, buf1[(3 * 11) + 3]; // "%d:%d:%d\0"
char *hlpargs[2]; char *hlpargs[3];
SpawnInfo sp; SpawnInfo sp;
/* need to tell helper which fd is for receiving the childstuff /* need to tell helper which fd is for receiving the childstuff
* and which fd to send response back on * and which fd to send response back on
*/ */
snprintf(buf1, sizeof(buf1), "%d:%d:%d", c->childenv[0], c->childenv[1], c->fail[1]); 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 */ /* NULL-terminated argv array.
hlpargs[0] = buf1; * argv[0] contains path to jspawnhelper, to follow conventions.
hlpargs[1] = 0; * 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 /* Following items are sent down the pipe to the helper
* after it is spawned. * after it is spawned.