From 979b92deb83c093d45e7a3fa15bf8f0e45a9050d Mon Sep 17 00:00:00 2001 From: jordan Date: Thu, 4 May 2023 22:21:55 -0500 Subject: [PATCH 1/2] Fix session ticket leak in wolfSSL_Cleanup --- src/ssl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index abd78681e..c4354289f 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -14356,12 +14356,9 @@ int wolfSSL_Cleanup(void) { int ret = WOLFSSL_SUCCESS; /* Only the first error will be returned */ int release = 0; -#if !defined(NO_SESSION_CACHE) && (defined(ENABLE_SESSION_CACHE_ROW_LOCK) || \ - defined(SESSION_CACHE_DYNAMIC_MEM)) +#if !defined(NO_SESSION_CACHE) int i; - #ifdef SESSION_CACHE_DYNAMIC_MEM int j; - #endif #endif WOLFSSL_ENTER("wolfSSL_Cleanup"); @@ -14406,17 +14403,20 @@ int wolfSSL_Cleanup(void) } session_lock_valid = 0; #endif - #ifdef SESSION_CACHE_DYNAMIC_MEM for (i = 0; i < SESSION_ROWS; i++) { for (j = 0; j < SESSIONS_PER_ROW; j++) { + #ifdef SESSION_CACHE_DYNAMIC_MEM if (SessionCache[i].Sessions[j]) { + EvictSessionFromCache(SessionCache[i].Sessions[j]); XFREE(SessionCache[i].Sessions[j], SessionCache[i].heap, DYNAMIC_TYPE_SESSION); SessionCache[i].Sessions[j] = NULL; } + #else + EvictSessionFromCache(&SessionCache[i].Sessions[j]); + #endif } } - #endif #ifndef NO_CLIENT_CACHE if ((clisession_mutex_valid == 1) && (wc_FreeMutex(&clisession_mutex) != 0)) { From 9d05a4f2edbc6b3224c225e9e11c9216494ac361 Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 17 May 2023 16:25:27 -0400 Subject: [PATCH 2/2] Don't orphan ticBuff pointer in wolfSSL_DupSessionEx --- src/ssl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index c4354289f..2d693cd2e 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -21455,8 +21455,8 @@ static int wolfSSL_DupSessionEx(const WOLFSSL_SESSION* input, * the static buffer. */ if (ticBuff != NULL) { if (ticLenAlloc >= input->ticketLen) { - output->ticket = output->staticTicket; - output->ticketLenAlloc = 0; + output->ticket = ticBuff; + output->ticketLenAlloc = ticLenAlloc; } else { WOLFSSL_MSG("ticket dynamic buffer too small but we are "