X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fvasnprintf.c;h=ff80857305864a2ac93d98d7159af9048a67c7cf;hb=8912e6d4dccc2f3b7d125229ef9ee05dda1f36ed;hp=0fa24708fe80aa96212f25c60d633106a4b2bd68;hpb=325083763c51b8d7beb17a03e1db01a76fb98b07;p=gnulib.git diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 0fa24708f..ff8085730 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -40,7 +40,7 @@ #include /* abort(), malloc(), realloc(), free() */ #include /* memcpy(), strlen() */ #include /* errno */ -#include /* CHAR_BIT */ +#include /* CHAR_BIT, INT_MAX */ #include /* DBL_MAX_EXP, LDBL_MAX_EXP */ #if WIDE_CHAR_VERSION # include "wprintf-parse.h" @@ -862,8 +862,19 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar free (buf_malloced); CLEANUP (); *lengthp = length; + if (length > INT_MAX) + goto length_overflow; return result; + length_overflow: + /* We could produce such a big string, but its length doesn't fit into + an 'int'. POSIX says that snprintf() fails with errno = EOVERFLOW in + this case. */ + if (result != resultbuf) + free (result); + errno = EOVERFLOW; + return NULL; + out_of_memory: if (!(result == resultbuf || result == NULL)) free (result);