From 81df85a1b528d4edb9ab98b37fb6c6244430b6c4 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 4 Mar 2022 00:00:00 -0600 Subject: [PATCH] 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 --- ps/sortformat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ps/sortformat.c b/ps/sortformat.c index da1783d6..2293aa95 100644 --- a/ps/sortformat.c +++ b/ps/sortformat.c @@ -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; }