From 7e9896d162eb5e284a172c57f3c6c6ddcc09fd1f Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Wed, 27 Apr 2022 22:04:32 +0200 Subject: [PATCH] Only clear session when we didn't complete a handshake - Allow overriding buffer size with `WOLFSSL_MSG_EX_BUF_SZ` - Allow disabling `WOLFSSL_MSG_EX` by defining `NO_WOLFSSL_MSG_EX` --- src/ssl.c | 15 +++++++++------ wolfcrypt/src/logging.c | 10 +++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index c159b283b..563a14168 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -17976,6 +17976,15 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, return WOLFSSL_FAILURE; } + if (!ssl->options.handShakeDone) { + /* Only reset the session if we didn't complete a handshake */ + wolfSSL_SESSION_free(ssl->session); + ssl->session = wolfSSL_NewSession(ssl->heap); + if (ssl->session == NULL) { + return WOLFSSL_FAILURE; + } + } + ssl->options.isClosed = 0; ssl->options.connReset = 0; ssl->options.sentNotify = 0; @@ -18000,12 +18009,6 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, InitX509(&ssl->peerCert, 0, ssl->heap); #endif - wolfSSL_SESSION_free(ssl->session); - ssl->session = wolfSSL_NewSession(ssl->heap); - if (ssl->session == NULL) { - return WOLFSSL_FAILURE; - } - return WOLFSSL_SUCCESS; } diff --git a/wolfcrypt/src/logging.c b/wolfcrypt/src/logging.c index 905509fa0..ec4173653 100644 --- a/wolfcrypt/src/logging.c +++ b/wolfcrypt/src/logging.c @@ -364,16 +364,20 @@ static void wolfssl_log(const int logLevel, const char *const logMessage) } #ifndef WOLFSSL_DEBUG_ERRORS_ONLY + +#if !defined(_WIN32) && defined(XVSNPRINTF) && !defined(NO_WOLFSSL_MSG_EX) +#include /* for var args */ +#ifndef WOLFSSL_MSG_EX_BUF_SZ +#define WOLFSSL_MSG_EX_BUF_SZ 100 +#endif #ifdef __clang__ /* tell clang argument 1 is format */ __attribute__((__format__ (__printf__, 1, 0))) #endif -#if !defined(_WIN32) && defined(XVSNPRINTF) -#include /* for var args */ void WOLFSSL_MSG_EX(const char* fmt, ...) { if (loggingEnabled) { - char msg[100]; + char msg[WOLFSSL_MSG_EX_BUF_SZ]; int written; va_list args; va_start(args, fmt);