]> granicus.if.org Git - procps-ng/commitdiff
0052-ps/output.c: Handle negative snprintf() return value.
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)
May happen if strlen(src) > INT_MAX for example. This patch prevents
escaped_copy() from increasing maxroom and returning -1 (= number of
bytes consumed in dst).

---------------------------- adapted for newlib branch
. formerly applied to proc/escape.c
. function was moved to ps/output.c

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

index a75e234cdd5ce8e911f464b13e754294e19f586a..503dba64066f9179ac5c80e6e68a791d1bba5095 100644 (file)
@@ -126,6 +126,10 @@ static int escaped_copy(char *restrict dst, const char *restrict src, int bufsiz
     if (bufsize > *maxroom+1)
         bufsize = *maxroom+1;
     n = snprintf(dst, bufsize, "%s", src);
+    if (n < 0) {
+        *dst = '\0';
+        return 0;
+    }
     if (n >= bufsize)
         n = bufsize-1;
     *maxroom -= n;