]> granicus.if.org Git - procps-ng/commitdiff
proc/escape.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>
Fri, 18 May 2018 21:32:21 +0000 (07:32 +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).

proc/escape.c

index 82cd68210b73133ccf94db0bc7926403671d443d..5cd687794e6ec9d6705d9a4ec7efad2481a3c171 100644 (file)
@@ -251,6 +251,10 @@ int escaped_copy(char *restrict dst, const char *restrict src, int bufsize, int
   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;
   return n;