Skip to content

Commit 15bd75d

Browse files
committed
TLS 1.3: address review of post-handshake defrag buffer relocation
- wolfSSL_ResourceFree(): reset pendingMsgSz/pendingMsgOffset/pendingMsgType alongside freeing ssl->pendingMsg. - test_tls13_fragmented_session_ticket: ForceZero() preMasterSecret and the Arrays struct before freeing so WOLFSSL_CHECK_MEM_ZERO builds do not abort.
1 parent d9b05f0 commit 15bd75d

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/internal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8864,6 +8864,10 @@ void wolfSSL_ResourceFree(WOLFSSL* ssl)
88648864
* used to reassemble post-handshake messages; release it here. */
88658865
XFREE(ssl->pendingMsg, ssl->heap, DYNAMIC_TYPE_ARRAYS);
88668866
ssl->pendingMsg = NULL;
8867+
/* Reset the rest of the defrag state for a possible object reuse. */
8868+
ssl->pendingMsgSz = 0;
8869+
ssl->pendingMsgOffset = 0;
8870+
ssl->pendingMsgType = 0;
88678871
FreeKeyExchange(ssl);
88688872
#ifdef WOLFSSL_ASYNC_IO
88698873
/* Cleanup async */

tests/api/test_tls13.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5689,7 +5689,14 @@ int test_tls13_fragmented_session_ticket(void)
56895689
* configurations that already release the arrays (e.g. no HAVE_SESSION_TICKET)
56905690
* they are NULL at this point and the free is skipped. */
56915691
if (EXPECT_SUCCESS() && ssl_c->arrays != NULL) {
5692-
XFREE(ssl_c->arrays->preMasterSecret, ssl_c->heap, DYNAMIC_TYPE_SECRET);
5692+
/* Zero before freeing so WOLFSSL_CHECK_MEM_ZERO builds don't abort. */
5693+
if (ssl_c->arrays->preMasterSecret != NULL) {
5694+
ForceZero(ssl_c->arrays->preMasterSecret, ENCRYPT_LEN);
5695+
XFREE(ssl_c->arrays->preMasterSecret, ssl_c->heap,
5696+
DYNAMIC_TYPE_SECRET);
5697+
ssl_c->arrays->preMasterSecret = NULL;
5698+
}
5699+
ForceZero(ssl_c->arrays, sizeof(Arrays));
56935700
XFREE(ssl_c->arrays, ssl_c->heap, DYNAMIC_TYPE_ARRAYS);
56945701
ssl_c->arrays = NULL;
56955702
}

0 commit comments

Comments
 (0)