From fff2049c1bc7c627e11df8062ef1f96a7697954f Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Thu, 16 Oct 2014 19:26:41 -0400 Subject: [PATCH] Fix crash with built-in [v]asprintf(). * src/vasprintf.c (__gpgme_vasprintf): Copy the va_list. -- Not sure why it needs to be done. Maybe because of dereferencing the pointer while doing va_copy() int_vasprintf()? If we remove the _BSD_VA_LIST stuff and pass a regular va_list all is fine. --- src/vasprintf.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/vasprintf.c b/src/vasprintf.c index 326a2c35..18b1ef17 100644 --- a/src/vasprintf.c +++ b/src/vasprintf.c @@ -26,8 +26,6 @@ Boston, MA 02111-1307, USA. */ #include #include -#include "mem.h" - #ifndef va_copy /* According to POSIX, va_copy is a macro. */ #if defined (__GNUC__) && defined (__PPC__) \ @@ -42,7 +40,14 @@ Boston, MA 02111-1307, USA. */ #ifdef TEST +#define _gpgme_malloc malloc +#define _gpgme_calloc calloc +#define _gpgme_realloc realloc +#define _gpgme_strdup strdup +#define _gpgme_free free int global_total_width; +#else +#include "mem.h" #endif static int int_vasprintf (char **, const char *, va_list *); @@ -161,7 +166,17 @@ _gpgme_vasprintf (result, format, args) va_list args; #endif { - return int_vasprintf (result, format, &args); +#if defined (_BSD_VA_LIST_) && defined (__FreeBSD__) + _BSD_VA_LIST_ cp; +#else + va_list cp; +#endif + int ret; + + va_copy(cp, args); + ret = int_vasprintf (result, format, &cp); + va_end(cp); + return ret; }