ps: fix -o pid=PID,args interpreting entire "PID,args" as header

procps-ng 3.3.15 does not do this.
(It could, allowing commas in headers and requiring
"ps -opid=PID -oargs" form for this case, but it does not).

function                                             old     new   delta
parse_o                                              167     190     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-10-07 21:55:16 +02:00
parent 421c8767ba
commit eb048a450c

View File

@ -443,17 +443,19 @@ static void parse_o(char* opt)
opt = comma + 1; opt = comma + 1;
continue; continue;
} }
break; // opt points to last spec in comma separated list.
} // This one can have =HEADER part.
// opt points to last spec in comma separated list. new = new_out_t();
// This one can have =HEADER part. if (equal)
new = new_out_t(); *equal = '\0';
if (equal) *new = *find_out_spec(opt);
*equal = '\0'; if (!equal)
*new = *find_out_spec(opt); break;
if (equal) { *equal++ = '=';
*equal = '='; new->header = equal;
new->header = equal + 1; comma = strchr(equal, ',');
if (comma)
*comma = '\0';
// POSIX: the field widths shall be ... at least as wide as // POSIX: the field widths shall be ... at least as wide as
// the header text (default or overridden value). // the header text (default or overridden value).
// If the header text is null, such as -o user=, // If the header text is null, such as -o user=,
@ -461,10 +463,12 @@ static void parse_o(char* opt)
// default header text // default header text
if (new->header[0]) { if (new->header[0]) {
new->width = strlen(new->header); new->width = strlen(new->header);
print_header = 1;
} }
} else if (!comma)
print_header = 1; break;
//*comma = ','; /* no, new->header should stay NUL-terminated */
opt = comma + 1;
}
} }
static void alloc_line_buffer(void) static void alloc_line_buffer(void)