From: Micah Cowan Date: Sat, 12 Apr 2008 19:57:25 +0000 (-0700) Subject: Merging in the rest of Alex's bundle. X-Git-Tag: v1.13~430^2~2 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=4e288c5db5242cf5851e1d113824eae5d5fb0e02;hp=83ac6990ddecc54ca7f7479ba3aba95116d614bc Merging in the rest of Alex's bundle. --- diff --git a/src/ChangeLog b/src/ChangeLog index 7201511a..a2881858 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-04-11 Alexander Dergachev + + * utils.c (aprintf): Now we are setting limits (1 Mb) for text + buffer when we use non-C99 vsnprintf. + 2008-04-11 Micah Cowan * ftp.c (getftp, ftp_loop_internal): Don't append to an existing diff --git a/src/utils.c b/src/utils.c index 3fd1435e..af621402 100644 --- a/src/utils.c +++ b/src/utils.c @@ -159,6 +159,13 @@ sepstring (const char *s) vsnprintf until the correct size is found. Since Wget also ships a 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 * aprintf (const char *fmt, ...) { @@ -202,7 +209,19 @@ aprintf (const char *fmt, ...) if (n > -1) /* C99 */ size = n + 1; /* precisely what is needed */ 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, */ + logprintf (LOG_ALWAYS, + _("%s: aprintf: text buffer is too big (%ld bytes), \ +free already allocated memory and abort.\n"), + exec_name, size); /* printout a log message */ + abort (); /* and abort... */ + } + /* else, we continue to grow our buffer. */ + size <<= 1; /* twice the old size */ + } str = xrealloc (str, size); } #endif /* not HAVE_VASPRINTF */