ps: extend utf8 multibyte support to additional fields

Form its inception (back in May of 2011), escaped_copy
has always been a flawed function. It does not operate
on 'escaped' strings but instead treats all input as a
regular string incapable of containing utf8 sequences.

As such, it should only be used for strings guaranteed
to NOT contain multibyte characters (like supgid). For
all other strings, which could contain utf8 stuff, the
correct function should have been that escape_str guy.

So this commit changes nearly every escaped_copy call.

[ note: unlike the newlib guy, the master ps program ]
[ cannot properly handle utf8 multibyte sequences in ]
[ in the recently introduced 'exe' field shown below ]

Reference(s):
. Jun 2018, introduced 'exe' field
commit b556bf5ba8
. May 2011, original escaped_copy (cmdline, cgroup)
commit 7b0fc19e9d

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2020-12-24 00:00:00 -06:00 committed by Craig Small
parent 9165f79fc1
commit be22291257

View File

@ -404,7 +404,7 @@ static int pr_args(char *restrict const outbuf, const proc_t *restrict const pp)
rightward -= fh;
if(pp->cmdline && !bsd_c_option)
endp += escaped_copy(endp, *pp->cmdline, OUTBUF_SIZE_AT(endp), &rightward);
endp += escape_str(endp, *pp->cmdline, OUTBUF_SIZE_AT(endp), &rightward);
else
endp += escape_command(endp, pp, OUTBUF_SIZE_AT(endp), &rightward, ESC_DEFUNCT);
@ -431,7 +431,7 @@ static int pr_comm(char *restrict const outbuf, const proc_t *restrict const pp)
rightward -= fh;
if(pp->cmdline && unix_f_option)
endp += escaped_copy(endp, *pp->cmdline, OUTBUF_SIZE_AT(endp), &rightward);
endp += escape_str(endp, *pp->cmdline, OUTBUF_SIZE_AT(endp), &rightward);
else
endp += escape_command(endp, pp, OUTBUF_SIZE_AT(endp), &rightward, ESC_DEFUNCT);
@ -448,14 +448,14 @@ static int pr_comm(char *restrict const outbuf, const proc_t *restrict const pp)
static int pr_cgname(char *restrict const outbuf, const proc_t *restrict const pp){
int rightward = max_rightward;
escaped_copy(outbuf, pp->cgname, OUTBUF_SIZE, &rightward);
escape_str(outbuf, pp->cgname, OUTBUF_SIZE, &rightward);
return max_rightward-rightward;
}
static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) {
int rightward = max_rightward;
escaped_copy(outbuf, *pp->cgroup, OUTBUF_SIZE, &rightward);
escape_str(outbuf, *pp->cgroup, OUTBUF_SIZE, &rightward);
return max_rightward-rightward;
}
@ -1208,7 +1208,7 @@ static int pr_supgid(char *restrict const outbuf, const proc_t *restrict const p
static int pr_supgrp(char *restrict const outbuf, const proc_t *restrict const pp){
int rightward = max_rightward;
escaped_copy(outbuf, pp->supgrp, OUTBUF_SIZE, &rightward);
escape_str(outbuf, pp->supgrp, OUTBUF_SIZE, &rightward);
return max_rightward-rightward;
}