top: address a defect with the library PROC_PID flag
The library does not weed out potential duplicate PID values when sampling with the PROC_PID flag. This was treated as merely an inefficiency by top and safely ignored prior to the advent of forest view mode. Now, however, if the -p switch duplicates certain PIDs, *and* those processes have no PPID, *and* top's forest view mode is active or activated, then a SEGV will be generated (and caught). This rather obscure buglet is thus limited to pid #1 (/sbin/init) and pid #2 (kthreadd). With any other duplicate PIDs the worse case scenario was a '?' in place of the usual forest view artwork. This commit silently ignores any duplicate process ids and thereby avoids the potential segmemtation fault. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
421b08a4df
commit
39243fe306
16
top/top.c
16
top/top.c
@ -2420,20 +2420,20 @@ static void parse_args (char **args) {
|
|||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
|
if (Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
|
||||||
do {
|
do { int i, pid;
|
||||||
if (cp[1]) cp++;
|
if (cp[1]) cp++;
|
||||||
else if (*args) cp = *args++;
|
else if (*args) cp = *args++;
|
||||||
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
|
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
|
||||||
if (Monpidsidx >= MONPIDMAX)
|
if (Monpidsidx >= MONPIDMAX)
|
||||||
error_exit(fmtmk(N_fmt(LIMIT_exceed_fmt), MONPIDMAX));
|
error_exit(fmtmk(N_fmt(LIMIT_exceed_fmt), MONPIDMAX));
|
||||||
if (1 != sscanf(cp, "%d", &Monpids[Monpidsidx])
|
if (1 != sscanf(cp, "%d", &pid) || 0 > pid)
|
||||||
|| 0 > Monpids[Monpidsidx])
|
|
||||||
error_exit(fmtmk(N_fmt(BAD_mon_pids_fmt), cp));
|
error_exit(fmtmk(N_fmt(BAD_mon_pids_fmt), cp));
|
||||||
if (!Monpids[Monpidsidx])
|
if (!pid) pid = getpid();
|
||||||
Monpids[Monpidsidx] = getpid();
|
for (i = 0; i < Monpidsidx; i++)
|
||||||
Monpidsidx++;
|
if (Monpids[i] == pid) goto next_pid;
|
||||||
if (!(p = strchr(cp, ',')))
|
Monpids[Monpidsidx++] = pid;
|
||||||
break;
|
next_pid:
|
||||||
|
if (!(p = strchr(cp, ','))) break;
|
||||||
cp = p;
|
cp = p;
|
||||||
} while (*cp);
|
} while (*cp);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user