]> granicus.if.org Git - procps-ng/commitdiff
0058-ps/output.c: Replace strcpy() with snprintf() in show_one_proc().
authorQualys Security Advisory <qsa@qualys.com>
Thu, 1 Jan 1970 00:00:00 +0000 (00:00 +0000)
committerCraig Small <csmall@enc.com.au>
Sat, 9 Jun 2018 11:45:38 +0000 (21:45 +1000)
This strcpy() should normally not overflow outbuf, but names can be
overridden (via -o). Also, check "amount" in all cases.

---------------------------- adapted for newlib branch
. we don't use that 'likely/unlikely' crap in newlib

Signed-off-by: Jim Warner <james.warner@comcast.net>
ps/output.c

index 8b118d27243aec760d616fbabafa5d3370d5d397..a90b162394a7019a8da60b7fe75397e1cb1b7ceb 100644 (file)
@@ -1950,7 +1950,10 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
 
     /* prepare data and calculate leftpad */
     if(p && fmt->pr) amount = (*fmt->pr)(outbuf,p);
-    else amount = strlen(strcpy(outbuf, fmt->name)); /* AIX or headers */
+    else amount = snprintf(outbuf, OUTBUF_SIZE, "%s", fmt->name); /* AIX or headers */
+
+    if(amount < 0) outbuf[amount = 0] = '\0';
+    else if(amount >= OUTBUF_SIZE) outbuf[amount = OUTBUF_SIZE-1] = '\0';
 
     switch((fmt->flags) & CF_JUST_MASK){
     case 0:  /* for AIX, assigned outside this file */