]> granicus.if.org Git - procps-ng/commitdiff
ps: swat insidious bug with the %cpu' format specifier
authorJim Warner <james.warner@comcast.net>
Fri, 4 Mar 2022 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Sun, 6 Mar 2022 03:52:34 +0000 (14:52 +1100)
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>
ps/sortformat.c

index da1783d6a9f803a25e4a37847633bf544710c136..2293aa950b6686524db47d0cd28cd82ab61eb2b0 100644 (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;
 }