0052-ps/output.c: Handle negative snprintf() return value.
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>
This commit is contained in:
parent
f44fe715bd
commit
9caf95c0bd
@ -126,6 +126,10 @@ static int escaped_copy(char *restrict dst, const char *restrict src, int bufsiz
|
|||||||
if (bufsize > *maxroom+1)
|
if (bufsize > *maxroom+1)
|
||||||
bufsize = *maxroom+1;
|
bufsize = *maxroom+1;
|
||||||
n = snprintf(dst, bufsize, "%s", src);
|
n = snprintf(dst, bufsize, "%s", src);
|
||||||
|
if (n < 0) {
|
||||||
|
*dst = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (n >= bufsize)
|
if (n >= bufsize)
|
||||||
n = bufsize-1;
|
n = bufsize-1;
|
||||||
*maxroom -= n;
|
*maxroom -= n;
|
||||||
|
Loading…
Reference in New Issue
Block a user