]> granicus.if.org Git - procps-ng/commitdiff
ps/output.c: Always null-terminate outbuf 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>
Fri, 18 May 2018 21:32:21 +0000 (07:32 +1000)
Before "strlen(outbuf)", if one of the pr_*() functions forgot to do it.
This prevents an out-of-bounds read in strlen(), and an out-of-bounds
write in "outbuf[sz] = '\n'". Another solution would be to replace
strlen() with strnlen(), but this is not used anywhere else in the
code-base and may not exist in all libc's.

ps/output.c

index a60c98e8eaa3330a70686a246fabde42ad6d8447..e718f198fd5921073824696826df7093c6f20f29 100644 (file)
@@ -2120,6 +2120,7 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
     if(unlikely(space>SPACE_AMOUNT)) space=SPACE_AMOUNT;  // only so much available
 
     /* real size -- don't forget in 'amount' is number of cells */
+    outbuf[OUTBUF_SIZE-1] = '\0';
     sz = strlen(outbuf);
 
     /* print data, set x position stuff */