mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
* utils.c (aprintf): Now we are setting limits (1 Mb) for text buffer when we use non-C99 vsnprintf.
This commit is contained in:
parent
9ce3a8c0c8
commit
311f76645f
@ -1,3 +1,8 @@
|
|||||||
|
2008-04-11 Alexander Dergachev <cy6erbr4in@gmail.com>
|
||||||
|
|
||||||
|
* utils.c (aprintf): Now we are setting limits (1 Mb) for text
|
||||||
|
buffer when we use non-C99 vsnprintf.
|
||||||
|
|
||||||
2008-04-10 Alexander Dergachev <cy6erbr4in@gmail.com>
|
2008-04-10 Alexander Dergachev <cy6erbr4in@gmail.com>
|
||||||
|
|
||||||
* xmalloc.c, xmalloc.h (memfatal): Now exported; accepts an
|
* xmalloc.c, xmalloc.h (memfatal): Now exported; accepts an
|
||||||
|
17
src/utils.c
17
src/utils.c
@ -159,6 +159,13 @@ sepstring (const char *s)
|
|||||||
vsnprintf until the correct size is found. Since Wget also ships a
|
vsnprintf until the correct size is found. Since Wget also ships a
|
||||||
fallback implementation of vsnprintf, this should be portable. */
|
fallback implementation of vsnprintf, this should be portable. */
|
||||||
|
|
||||||
|
/* Constant is using for limits memory allocation for text buffer.
|
||||||
|
Applicable in situation when: vasprintf is not available in the system
|
||||||
|
and vsnprintf return -1 when long line is truncated (in old versions of
|
||||||
|
glibc and in other system where C99 doesn`t support) */
|
||||||
|
|
||||||
|
#define FMT_MAX_LENGTH 1048576
|
||||||
|
|
||||||
char *
|
char *
|
||||||
aprintf (const char *fmt, ...)
|
aprintf (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -202,7 +209,15 @@ aprintf (const char *fmt, ...)
|
|||||||
if (n > -1) /* C99 */
|
if (n > -1) /* C99 */
|
||||||
size = n + 1; /* precisely what is needed */
|
size = n + 1; /* precisely what is needed */
|
||||||
else
|
else
|
||||||
size <<= 1; /* twice the old size */
|
{
|
||||||
|
if (size >= FMT_MAX_LENGTH) /* We have a huge buffer, */
|
||||||
|
{ /* maybe we have some wrong format string? */
|
||||||
|
free (str); /* In this case we must free already allocated memory, */
|
||||||
|
return NULL; /* and return NULL pointer... */
|
||||||
|
}
|
||||||
|
/* else, we continue to grow our buffer. */
|
||||||
|
size <<= 1; /* twice the old size */
|
||||||
|
}
|
||||||
str = xrealloc (str, size);
|
str = xrealloc (str, size);
|
||||||
}
|
}
|
||||||
#endif /* not HAVE_VASPRINTF */
|
#endif /* not HAVE_VASPRINTF */
|
||||||
|
Loading…
Reference in New Issue
Block a user