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:
Diomidis Spinellis 2006-12-03 17:50:21 +00:00
parent 34785a9fc0
commit f88b45d7df
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=164852

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;
}
}