From be2229125736521cff5d42f9da764c7205582b7f Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 24 Dec 2020 00:00:00 -0600 Subject: [PATCH] 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 b556bf5ba82c7e593eb682bbf836c2bc444b2e7d . May 2011, original escaped_copy (cmdline, cgroup) commit 7b0fc19e9d28380dc9790615b93bc3653d6d686e Signed-off-by: Jim Warner --- ps/output.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ps/output.c b/ps/output.c index bc11600d..ad4c36c7 100644 --- a/ps/output.c +++ b/ps/output.c @@ -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; }