diff --git a/ChangeLog b/ChangeLog index e6a0d94f7be67f301b12cb4678fb59339f07562f..370dfbaa8c83812b73794ec36db18632d01bc099 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2005-11-15 Kevin P. Fleming <kpfleming@limerick.digium.com> + * astmm.c (__ast_vasprintf): don't re-use the ap list without copying it; that's not safe on some platforms (issue #5035) + * doc/README.backtrace: add note about properly building Asterisk to be able to produce backtraces; wrap text and remove DOS line endings * channels/chan_sip.c (add_codec_to_sdp): add 'annexb=no' to G.729A SDP (issue #5539) diff --git a/astmm.c b/astmm.c index d1692de27d41528e7088db51662e386e425dfbcd..3f94e05fadbc5928c5c9314a8f9c46d68b685c0b 100755 --- a/astmm.c +++ b/astmm.c @@ -254,21 +254,20 @@ char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func) { - int n, size = strlen(fmt) + 1; - if ((*strp = __ast_alloc_region(size, FUNC_VASPRINTF, file, lineno, func)) == NULL) - return -1; - for (;;) { - n = vsnprintf(*strp, size, fmt, ap); - if (n > -1 && n < size) - return n; - if (n > -1) { /* glibc 2.1 */ - size = n+1; - } else { /* glibc 2.0 */ - size *= 2; - } - if ((*strp = __ast_realloc(*strp, size, file, lineno, func)) == NULL) - return -1; - } + int size; + va_list ap2; + char s; + + *strp = NULL; + va_copy(ap2, ap); + size = vsnprintf(&s, 1, fmt, ap2); + va_end(ap2); + *strp = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func); + if (!*strp) + return -1; + vsnprintf(*strp, size + 1, fmt, ap); + + return size; } static int handle_show_memory(int fd, int argc, char *argv[])