Merge pull request #4532 from embhorn/zd13139

Fix mem leak in HandleTlsResumption
This commit is contained in:
David Garske
2021-11-08 08:39:45 -08:00
committed by GitHub

View File

@@ -29131,25 +29131,31 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
* Session tickets are checked for validity based on the time each ticket * Session tickets are checked for validity based on the time each ticket
* was created, timeout value and the current time. If the tickets are * was created, timeout value and the current time. If the tickets are
* judged expired, falls back to full-handshake. If you want disable this * judged expired, falls back to full-handshake. If you want disable this
* sessin ticket validation check in TLS1.2 and below, define * session ticket validation check in TLS1.2 and below, define
* WOLFSSL_NO_TICKET_EXPRE. * WOLFSSL_NO_TICKET_EXPRE.
*/ */
int HandleTlsResumption(WOLFSSL* ssl, int bogusID, Suites* clSuites) int HandleTlsResumption(WOLFSSL* ssl, int bogusID, Suites* clSuites)
{ {
int ret = 0; int ret = 0;
WOLFSSL_SESSION* session; WOLFSSL_SESSION* session;
#ifdef HAVE_EXT_CACHE
byte gotSess = 0;
#endif
(void)bogusID; (void)bogusID;
session = GetSession(ssl, ssl->arrays->masterSecret, 1);
#ifdef HAVE_SESSION_TICKET #ifdef HAVE_SESSION_TICKET
if (ssl->options.useTicket == 1) { if (ssl->options.useTicket == 1) {
session = &ssl->session; session = &ssl->session;
} else if (bogusID == 1 && ssl->options.rejectTicket == 0) { } else if (bogusID == 1 && ssl->options.rejectTicket == 0) {
WOLFSSL_MSG("Bogus session ID without session ticket"); WOLFSSL_MSG("Bogus session ID without session ticket");
return BUFFER_ERROR; return BUFFER_ERROR;
} } else
#endif #endif
{
session = GetSession(ssl, ssl->arrays->masterSecret, 1);
#ifdef HAVE_EXT_CACHE
gotSess = 1;
#endif
}
if (!session) { if (!session) {
WOLFSSL_MSG("Session lookup for resume failed"); WOLFSSL_MSG("Session lookup for resume failed");
ssl->options.resuming = 0; ssl->options.resuming = 0;
@@ -29180,14 +29186,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
#ifdef WOLFSSL_EXTRA_ALERTS #ifdef WOLFSSL_EXTRA_ALERTS
SendAlert(ssl, alert_fatal, handshake_failure); SendAlert(ssl, alert_fatal, handshake_failure);
#endif #endif
#ifdef HAVE_EXT_CACHE ret = EXT_MASTER_SECRET_NEEDED_E;
wolfSSL_SESSION_free(session);
#endif
return EXT_MASTER_SECRET_NEEDED_E;
} }
#ifdef HAVE_EXT_CACHE
wolfSSL_SESSION_free(session);
#endif
} }
else { else {
#ifndef NO_RESUME_SUITE_CHECK #ifndef NO_RESUME_SUITE_CHECK
@@ -29205,23 +29205,21 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
#ifdef WOLFSSL_EXTRA_ALERTS #ifdef WOLFSSL_EXTRA_ALERTS
SendAlert(ssl, alert_fatal, illegal_parameter); SendAlert(ssl, alert_fatal, illegal_parameter);
#endif #endif
return UNSUPPORTED_SUITE; ret = UNSUPPORTED_SUITE;
} }
#endif #endif
#ifdef HAVE_EXT_CACHE if (ret == 0) {
wolfSSL_SESSION_free(session);
#endif
if (MatchSuite(ssl, clSuites) < 0) { if (MatchSuite(ssl, clSuites) < 0) {
WOLFSSL_MSG("Unsupported cipher suite, ClientHello"); WOLFSSL_MSG("Unsupported cipher suite, ClientHello");
return UNSUPPORTED_SUITE; ret = UNSUPPORTED_SUITE;
} }
}
ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->serverRandom, if (ret == 0) {
RAN_LEN); ret = wc_RNG_GenerateBlock(ssl->rng,
if (ret != 0) ssl->arrays->serverRandom, RAN_LEN);
return ret; }
if (ret == 0) {
#ifdef NO_OLD_TLS #ifdef NO_OLD_TLS
ret = DeriveTlsKeys(ssl); ret = DeriveTlsKeys(ssl);
#else #else
@@ -29234,6 +29232,13 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
#endif #endif
ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE;
} }
}
#ifdef HAVE_EXT_CACHE
if (gotSess) {
wolfSSL_SESSION_free(session);
}
#endif
return ret; return ret;
} }