diff --git a/src/ssl.c b/src/ssl.c index daba0efd6..039aac212 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -26,7 +26,7 @@ #include #if defined(OPENSSL_EXTRA) && !defined(_WIN32) - /* turn on GNU extensions for vasprintf with wolfSSL_BIO_printf */ + /* turn on GNU extensions for XVASPRINTF with wolfSSL_BIO_printf */ #undef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -26425,14 +26425,27 @@ int wolfSSL_BIO_printf(WOLFSSL_BIO* bio, const char* format, ...) #if defined(OPENSSL_EXTRA) && !defined(_WIN32) case WOLFSSL_BIO_SSL: { + int count; char* pt = NULL; - ret = vasprintf(&pt, format, args); - if (ret > 0 && pt != NULL) { - wolfSSL_BIO_write(bio, pt, ret); - } - if (pt != NULL) { - free(pt); + va_list copy; + + va_copy(copy, args); + count = vsnprintf(NULL, 0, format, args); + if (count >= 0) + { + pt = (char*)XMALLOC(count + 1, bio->heap, + DYNAMIC_TYPE_TMP_BUFFER); + if (pt != NULL) + { + count = vsnprintf(pt, count + 1, format, copy); + if (count >= 0) + { + ret = wolfSSL_BIO_write(bio, pt, count); + } + XFREE(pt, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); + } } + va_end(copy); } break; #endif