Skip to content

Commit f042863

Browse files
Merge pull request #6807 from kareem-wolfssl/zd16715
Prevent current handshake counter from underflowing.
2 parents 237d10a + df6a65e commit f042863

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/internal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8210,7 +8210,7 @@ void SSL_ResourceFree(WOLFSSL* ssl)
82108210
if (FreeFixedIO(ctx_heap, &(ssl_hint->inBuf)) != 1) {
82118211
WOLFSSL_MSG("Error freeing fixed output buffer");
82128212
}
8213-
if (ssl_hint->haFlag) { /* check if handshake count has been decreased*/
8213+
if (ssl_hint->haFlag && ctx_heap->curHa > 0) { /* check if handshake count has been decreased*/
82148214
ctx_heap->curHa--;
82158215
}
82168216
wc_UnLockMutex(&(ctx_heap->memory_mutex));
@@ -8464,7 +8464,9 @@ void FreeHandshakeResources(WOLFSSL* ssl)
84648464
if (wc_LockMutex(&(ctx_heap->memory_mutex)) != 0) {
84658465
WOLFSSL_MSG("Bad memory_mutex lock");
84668466
}
8467-
ctx_heap->curHa--;
8467+
if (ctx_heap->curHa > 0) {
8468+
ctx_heap->curHa--;
8469+
}
84688470
ssl_hint->haFlag = 0; /* set to zero since handshake has been dec */
84698471
wc_UnLockMutex(&(ctx_heap->memory_mutex));
84708472
#ifdef WOLFSSL_HEAP_TEST

0 commit comments

Comments
 (0)