Fix vsnprintf(3) memory leak for size == 0.

PR:             bin/36175
Obtained from:  OpenBSD
Reviewed by:    silence on -audit
MFC after:      5 days
This commit is contained in:
Maxim Konovalov 2002-09-17 11:28:24 +00:00
parent 1cf4349926
commit 48eaac247f

View File

@ -50,6 +50,7 @@ vsnprintf(char * __restrict str, size_t n, const char * __restrict fmt,
{
size_t on;
int ret;
char dummy;
FILE f;
struct __sFILEX ext;
@ -58,6 +59,11 @@ vsnprintf(char * __restrict str, size_t n, const char * __restrict fmt,
n--;
if (n > INT_MAX)
n = INT_MAX;
/* Stdio internals do not deal correctly with zero length buffer */
if (n == 0) {
str = &dummy;
n = 1;
}
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;