Skip to content

Commit

Permalink
SID can be 0 before PID 1 calls setsid()
Browse files Browse the repository at this point in the history
  • Loading branch information
landley committed Oct 9, 2023
1 parent 5f153b5 commit 94913b5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions toys/posix/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ static int get_ps(struct dirtree *new)

// Store end of argv[0] so ARGS and CMDLINE can differ.
// We do it for each file string slot but last is cmdline, which sticks.
slot[SLOT_argv0len] = temp ? temp : len; // Position of _first_ NUL
slot[SLOT_argv0len] = temp ? : len; // Position of _first_ NUL
}

// Each case above calculated/retained len, so we don't need to re-strlen.
Expand Down Expand Up @@ -1166,8 +1166,9 @@ static char *parse_rest(void *data, char *str, int len)
if (pl==&TT.ss && ll[pl->len]==0) ll[pl->len] = getsid(0);
}

// PID can't be zero but SID can be 0 before the init task calls setsid().
if (pl==&TT.pp || pl==&TT.ss) {
if (num && ll[pl->len]>0) {
if (num && ll[pl->len]>-(pl==&TT.ss)) {
pl->len++;

return 0;
Expand Down

0 comments on commit 94913b5

Please sign in to comment.