@@ -3567,6 +3567,11 @@ static int test_wolfSSL_CTX_add1_chain_cert(void)
35673567 }
35683568
35693569 ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
3570+ /* add1 must increment ref count (was 1, now 2). Verifies the
3571+ * up_ref return value is assigned, not just compared. */
3572+ if (EXPECT_SUCCESS() && x509 != NULL) {
3573+ ExpectIntEQ(wolfSSL_RefCur(x509->ref), 2);
3574+ }
35703575 X509_free(x509);
35713576 x509 = NULL;
35723577 }
@@ -3586,6 +3591,10 @@ static int test_wolfSSL_CTX_add1_chain_cert(void)
35863591 }
35873592
35883593 ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
3594+ /* add1 must increment ref count (was 1, now 2) */
3595+ if (EXPECT_SUCCESS() && x509 != NULL) {
3596+ ExpectIntEQ(wolfSSL_RefCur(x509->ref), 2);
3597+ }
35893598 X509_free(x509);
35903599 x509 = NULL;
35913600 }
@@ -13310,6 +13319,64 @@ static int test_wolfSSL_tmp_dh(void)
1331013319 return EXPECT_RESULT();
1331113320}
1331213321
13322+ /* Tests SSL_CTX_set_tmp_dh with single-operand failure (p set, g missing)
13323+ * and wolfSSL_CTX_SetTmpDH_buffer with WOLFSSL_FILETYPE_ASN1 DER input. */
13324+ static int test_wolfSSL_tmp_dh_regression(void)
13325+ {
13326+ EXPECT_DECLS;
13327+ #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && !defined(NO_CERTS) && \
13328+ !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_TLS) && \
13329+ !defined(NO_WOLFSSL_SERVER)
13330+ SSL_CTX* ctx = NULL;
13331+
13332+ ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
13333+ ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
13334+ WOLFSSL_FILETYPE_PEM));
13335+ ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
13336+ WOLFSSL_FILETYPE_PEM));
13337+
13338+ #if defined(OPENSSL_ALL) || \
13339+ (defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L)
13340+ {
13341+ /* Test single-operand failure: DH with p but no g. */
13342+ DH* dh = NULL;
13343+ WOLFSSL_BIGNUM* p_bn = NULL;
13344+
13345+ ExpectNotNull(dh = wolfSSL_DH_new());
13346+ ExpectNotNull(p_bn = wolfSSL_BN_new());
13347+ ExpectIntEQ(wolfSSL_BN_set_word(p_bn, 0xFFFF), 1);
13348+ if (dh != NULL && p_bn != NULL) {
13349+ if (wolfSSL_DH_set0_pqg(dh, p_bn, NULL, NULL) == 1) {
13350+ p_bn = NULL; /* ownership transferred on success */
13351+ }
13352+ }
13353+ ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_FATAL_ERROR);
13354+ DH_free(dh);
13355+ wolfSSL_BN_free(p_bn);
13356+ }
13357+ #endif
13358+
13359+ /* Test ASN1/DER path through wolfSSL_CTX_SetTmpDH_buffer. */
13360+ {
13361+ byte derBuf[4096];
13362+ XFILE f = XBADFILE;
13363+ int derSz = 0;
13364+
13365+ ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
13366+ if (f != XBADFILE) {
13367+ derSz = (int)XFREAD(derBuf, 1, sizeof(derBuf), f);
13368+ XFCLOSE(f);
13369+ }
13370+ ExpectIntGT(derSz, 0);
13371+ ExpectIntEQ(wolfSSL_CTX_SetTmpDH_buffer(ctx, derBuf, (long)derSz,
13372+ WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
13373+ }
13374+
13375+ SSL_CTX_free(ctx);
13376+ #endif
13377+ return EXPECT_RESULT();
13378+ }
13379+
1331313380static int test_wolfSSL_ctrl(void)
1331413381{
1331513382 EXPECT_DECLS;
@@ -35649,6 +35716,7 @@ TEST_CASE testCases[] = {
3564935716 TEST_TLS13_DECLS,
3565035717
3565135718 TEST_DECL(test_wolfSSL_tmp_dh),
35719+ TEST_DECL(test_wolfSSL_tmp_dh_regression),
3565235720 TEST_DECL(test_wolfSSL_ctrl),
3565335721
3565435722 TEST_DECL(test_wolfSSL_get0_param),
0 commit comments