mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 19:54:40 +02:00
Replace use of vasprintf
This commit is contained in:
24
src/ssl.c
24
src/ssl.c
@@ -26150,14 +26150,26 @@ 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 = XVASPRINTF(&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 = 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
|
||||
|
@@ -493,63 +493,6 @@
|
||||
#endif /* _MSC_VER || __CYGWIN__ || __MINGW32__ */
|
||||
#endif /* USE_WINDOWS_API */
|
||||
|
||||
/* XVASPRINTF is used in ssl.c for wolfSSL_BIO_printf */
|
||||
#ifdef __GNUC__
|
||||
#define VASPRINTFCHECK __attribute__((format(printf, 2, 0)))
|
||||
#else
|
||||
#define VASPRINTFCHECK
|
||||
#endif /* __GNUC__ */
|
||||
#if (defined(sun) || defined(__sun) || defined(_AIX))
|
||||
#include <stdarg.h>
|
||||
VASPRINTFCHECK static WC_INLINE
|
||||
int xvasprintf(char **ret, const char *format, va_list args)
|
||||
{
|
||||
int count;
|
||||
char *buffer;
|
||||
va_list copy;
|
||||
va_copy(copy, args);
|
||||
|
||||
*ret = NULL;
|
||||
|
||||
count = vsnprintf(NULL, 0, format, args);
|
||||
if (count >= 0)
|
||||
{
|
||||
buffer = malloc(count + 1);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
count = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = vsnprintf(buffer, count + 1, format, copy);
|
||||
if (count < 0)
|
||||
{
|
||||
free(buffer);
|
||||
count = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ret = buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
va_end(copy);
|
||||
|
||||
return count;
|
||||
}
|
||||
#define XVASPRINTF xvasprintf
|
||||
#else
|
||||
#ifndef XVASPRINTF
|
||||
#if defined(NO_FILESYSTEM) && (defined(OPENSSL_EXTRA) || \
|
||||
defined(HAVE_PKCS7)) && !defined(NO_STDIO_FILESYSTEM)
|
||||
/* case where stdio is not included else where but is needed
|
||||
for vasprintf */
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#define XVASPRINTF vasprintf
|
||||
#endif
|
||||
#endif /* defined(sun) || defined(__sun) || defined(_AIX) */
|
||||
|
||||
#if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
|
||||
/* use only Thread Safe version of strtok */
|
||||
#if defined(USE_WOLF_STRTOK)
|
||||
|
Reference in New Issue
Block a user