Avoid "Use after free"

Warning 544767.5627232
This commit is contained in:
Andras Fekete
2024-01-19 10:47:38 -05:00
parent 2c162ffb97
commit 7069a1805a

View File

@@ -34558,9 +34558,11 @@ static int test_wolfSSL_tmp_dh(void)
BIO_free(bio); BIO_free(bio);
DSA_free(dsa); DSA_free(dsa);
DH_free(dh); DH_free(dh);
dh = NULL;
#if defined(WOLFSSL_DH_EXTRA) && \ #if defined(WOLFSSL_DH_EXTRA) && \
(defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)) (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH))
DH_free(dh2); DH_free(dh2);
dh2 = NULL;
#endif #endif
SSL_free(ssl); SSL_free(ssl);
SSL_CTX_free(ctx); SSL_CTX_free(ctx);
@@ -47143,6 +47145,7 @@ static int test_wolfSSL_PEM_read_DHparams(void)
XFCLOSE(fp); XFCLOSE(fp);
DH_free(dh); DH_free(dh);
dh = NULL;
#endif #endif
return EXPECT_RESULT(); return EXPECT_RESULT();
} }
@@ -47901,7 +47904,9 @@ static int test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
EVP_PKEY_free(pkey); EVP_PKEY_free(pkey);
DH_free(setDh); DH_free(setDh);
setDh = NULL;
DH_free(dh); DH_free(dh);
dh = NULL;
#endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */ #endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */
#endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */ #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
#endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */ #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
@@ -48071,6 +48076,7 @@ static int test_wolfSSL_CTX_ctrl(void)
BIO_free(bio); BIO_free(bio);
DSA_free(dsa); DSA_free(dsa);
DH_free(dh); DH_free(dh);
dh = NULL;
#endif #endif
#endif #endif
#ifdef HAVE_ECC #ifdef HAVE_ECC
@@ -48317,6 +48323,7 @@ static int test_wolfSSL_EVP_PKEY_keygen(void)
ASN1_INTEGER_free(asn1int); ASN1_INTEGER_free(asn1int);
DH_free(dh); DH_free(dh);
dh = NULL;
XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
EVP_PKEY_free(pkey); EVP_PKEY_free(pkey);
@@ -48405,6 +48412,7 @@ static int test_wolfSSL_EVP_PKEY_copy_parameters(void)
ExpectIntEQ(BN_cmp(g1, g2), 0); ExpectIntEQ(BN_cmp(g1, g2), 0);
DH_free(dh); DH_free(dh);
dh = NULL;
EVP_PKEY_free(copy); EVP_PKEY_free(copy);
EVP_PKEY_free(params); EVP_PKEY_free(params);
#endif #endif
@@ -49150,7 +49158,9 @@ static int test_wolfSSL_EVP_PKEY_param_check(void)
EVP_PKEY_CTX_free(ctx); EVP_PKEY_CTX_free(ctx);
EVP_PKEY_free(pkey); EVP_PKEY_free(pkey);
DH_free(setDh); DH_free(setDh);
setDh = NULL;
DH_free(dh); DH_free(dh);
dh = NULL;
#endif #endif
#endif #endif
return EXPECT_RESULT(); return EXPECT_RESULT();
@@ -58430,6 +58440,7 @@ static int test_wolfSSL_DH(void)
ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL)); ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0); ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0);
DH_free(dh); DH_free(dh);
dh = NULL;
#endif #endif
#endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */ #endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */
#endif /* OPENSSL_ALL */ #endif /* OPENSSL_ALL */
@@ -58584,6 +58595,7 @@ static int test_wolfSSL_DH(void)
ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS);
DH_free(dh); /* decrease ref count */ DH_free(dh); /* decrease ref count */
DH_free(dh); /* free WOLFSSL_DH */ DH_free(dh); /* free WOLFSSL_DH */
dh = NULL;
q = NULL; q = NULL;
ExpectNull((dh = DH_new_by_nid(NID_sha1))); ExpectNull((dh = DH_new_by_nid(NID_sha1)));
@@ -58593,16 +58605,19 @@ static int test_wolfSSL_DH(void)
#ifdef HAVE_FFDHE_2048 #ifdef HAVE_FFDHE_2048
ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048))); ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048)));
DH_free(dh); DH_free(dh);
dh = NULL;
q = NULL; q = NULL;
#endif #endif
#ifdef HAVE_FFDHE_3072 #ifdef HAVE_FFDHE_3072
ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072))); ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072)));
DH_free(dh); DH_free(dh);
dh = NULL;
q = NULL; q = NULL;
#endif #endif
#ifdef HAVE_FFDHE_4096 #ifdef HAVE_FFDHE_4096
ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096))); ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096)));
DH_free(dh); DH_free(dh);
dh = NULL;
q = NULL; q = NULL;
#endif #endif
#else #else
@@ -58802,6 +58817,7 @@ static int test_wolfSSL_DH_check(void)
ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0); ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME); ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
DH_free(dh); DH_free(dh);
dh = NULL;
#endif #endif
#endif /* !NO_DH && !NO_DSA */ #endif /* !NO_DH && !NO_DSA */
#endif #endif
@@ -59287,6 +59303,7 @@ static int test_wolfSSL_i2d_DHparams(void)
ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268); ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268);
DH_free(dh); DH_free(dh);
dh = NULL;
*buf = 0; *buf = 0;
#endif #endif
@@ -59316,6 +59333,7 @@ static int test_wolfSSL_i2d_DHparams(void)
ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396); ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396);
DH_free(dh); DH_free(dh);
dh = NULL;
#endif #endif
dh = DH_new(); dh = DH_new();
@@ -59323,6 +59341,7 @@ static int test_wolfSSL_i2d_DHparams(void)
pt2 = buf; pt2 = buf;
ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0); ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0);
DH_free(dh); DH_free(dh);
dh = NULL;
#endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */ #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
#endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */ #endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */
#endif #endif