@@ -10277,6 +10277,39 @@ static int test_wolfSSL_wolfSSL_UseSecureRenegotiation(void)
1027710277 return EXPECT_RESULT();
1027810278}
1027910279
10280+ /* TLSX_FreeAll frees the SecureRenegotiation struct but the cached pointer
10281+ * ssl->secure_renegotiation was not cleared, causing a use-after-free when
10282+ * queried after wolfSSL_clear(). */
10283+ static int test_wolfSSL_clear_secure_renegotiation(void)
10284+ {
10285+ EXPECT_DECLS;
10286+ #if (defined(HAVE_SECURE_RENEGOTIATION) || \
10287+ defined(HAVE_SERVER_RENEGOTIATION_INFO)) && \
10288+ (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
10289+ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS)
10290+ WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
10291+ WOLFSSL *ssl = wolfSSL_new(ctx);
10292+ long support;
10293+
10294+ ExpectNotNull(ctx);
10295+ ExpectNotNull(ssl);
10296+
10297+ ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl));
10298+ ExpectNotNull(ssl->secure_renegotiation);
10299+ if (ssl->secure_renegotiation != NULL)
10300+ ssl->secure_renegotiation->enabled = 1;
10301+
10302+ ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_clear(ssl));
10303+ support = wolfSSL_SSL_get_secure_renegotiation_support(ssl);
10304+ ExpectNull(ssl->secure_renegotiation);
10305+ ExpectIntEQ(WOLFSSL_FAILURE, support);
10306+
10307+ wolfSSL_free(ssl);
10308+ wolfSSL_CTX_free(ctx);
10309+ #endif
10310+ return EXPECT_RESULT();
10311+ }
10312+
1028010313/* Test reconnecting with a different ciphersuite after a renegotiation. */
1028110314static int test_wolfSSL_SCR_Reconnect(void)
1028210315{
@@ -36627,6 +36660,7 @@ TEST_CASE testCases[] = {
3662736660 TEST_DECL(test_TLSX_TCA_Find),
3662836661 TEST_DECL(test_TLSX_SNI_GetSize_overflow),
3662936662 TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
36663+ TEST_DECL(test_wolfSSL_clear_secure_renegotiation),
3663036664 TEST_DECL(test_wolfSSL_SCR_Reconnect),
3663136665 TEST_DECL(test_wolfSSL_SCR_check_enabled),
3663236666 TEST_DECL(test_tls_ext_duplicate),
0 commit comments