Prevent buffer overflow when forcibly terminating an escape character.

Obtained from:	OpenBSD
Note: In the case of a full buffer the OpenBSD implementation will
leave in the format string an invalid escape sequence.  This appears
to be harmless with our C library, but according to C99 this can
cause undefined behavior.

MFC after:      2 weeks
This commit is contained in:
dds 2006-12-03 17:50:21 +00:00
parent 552b6c0ead
commit af51ff2234

View File

@ -480,7 +480,9 @@ getformat(void)
else if (*p == '%' && *(p+1) == '%')
p++;
else if (*p == '%' && !*(p+1)) {
strcat(format, "%");
if (strlcat(format, "%", sizeof(format)) >=
sizeof(format))
errx(1, "-w word too long");
break;
}
}