ps: swat insidious bug with the %cpu' format specifier

Whoa, my head really hurts but this commit should help
with a speedy recovery hopefully, after it is applied.

If the '%cpu' field is used as a format specifier with
that 'o' option, you will encounter a SIGSEGV if there
is also an invalid argument on that same command line.

For example, try 'ps/pscommand -o %cpu,x' with newlib.
With any format specifier other than the '%cpu', there
is an error message, as would happen with '-o pcpu,x'.

For a 3.3.17 version of ps, there's no abend. Instead,
the program will just display a bunch of gobbledygook.
This boo-boo was found to exist as far back as v3.3.0.

[ ok, i am starting to feel very much better already ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-03-04 00:00:00 -06:00 committed by Craig Small
parent 2ac72e2e80
commit 81df85a1b5

View File

@ -313,7 +313,8 @@ static const char *format_parse(sf_node *sfn){
if(0) improper: err=_("improper format list");
if(0) badwidth: err=_("column widths must be unsigned decimal numbers");
if(0) notmacro: err=_("can not set width for a macro (multi-column) format specifier");
if(strchr(sfn->sf,'%')) err = aix_format_parse(sfn);
if (!err)
if(strchr(sfn->sf,'%')) err = aix_format_parse(sfn);
return err;
}