From df6a65e151a7e5c0f8f43fd8c7856f04be1f5966 Mon Sep 17 00:00:00 2001 From: Kareem Date: Fri, 22 Sep 2023 14:47:00 -0700 Subject: [PATCH] Prevent current handshake counter from underflowing. --- src/internal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index 7566fe93e..e249a95a7 100644 --- a/src/internal.c +++ b/src/internal.c @@ -8210,7 +8210,7 @@ void SSL_ResourceFree(WOLFSSL* ssl) if (FreeFixedIO(ctx_heap, &(ssl_hint->inBuf)) != 1) { WOLFSSL_MSG("Error freeing fixed output buffer"); } - if (ssl_hint->haFlag) { /* check if handshake count has been decreased*/ + if (ssl_hint->haFlag && ctx_heap->curHa > 0) { /* check if handshake count has been decreased*/ ctx_heap->curHa--; } wc_UnLockMutex(&(ctx_heap->memory_mutex)); @@ -8464,7 +8464,9 @@ void FreeHandshakeResources(WOLFSSL* ssl) if (wc_LockMutex(&(ctx_heap->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); } - ctx_heap->curHa--; + if (ctx_heap->curHa > 0) { + ctx_heap->curHa--; + } ssl_hint->haFlag = 0; /* set to zero since handshake has been dec */ wc_UnLockMutex(&(ctx_heap->memory_mutex)); #ifdef WOLFSSL_HEAP_TEST