Skip to content

Commit d789341

Browse files
committed
Add regression tests for group-setting and shared-cipher API guards
Extend test_tls13_apis with negative-count assertions for wolfSSL_CTX_set_groups and wolfSSL_set_groups, and NULL-groups assertions for wolfSSL_CTX_set1_groups and wolfSSL_set1_groups (tests/api/test_tls13.c). Add test_wolfSSL_get_shared_ciphers covering NULL ssl, NULL buf, and zero-length inputs (tests/api/test_tls.c).
1 parent 8cd77b5 commit d789341

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

tests/api/test_tls.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,3 +857,29 @@ int test_tls_set_curves_list_ecc_fallback(void)
857857
return EXPECT_RESULT();
858858
}
859859

860+
int test_wolfSSL_get_shared_ciphers(void)
861+
{
862+
EXPECT_DECLS;
863+
#if !defined(WOLFSSL_NO_TLS12) && !defined(NO_TLS)
864+
#ifndef NO_WOLFSSL_CLIENT
865+
WOLFSSL_CTX* ctx = NULL;
866+
WOLFSSL* ssl = NULL;
867+
char buf[32];
868+
869+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
870+
ExpectNotNull(ssl = wolfSSL_new(ctx));
871+
872+
/* NULL ssl - pre-existing guard; pins the contract. */
873+
ExpectNull(wolfSSL_get_shared_ciphers(NULL, buf, sizeof(buf)));
874+
/* NULL buf - primary regression case (pre-fix: XMEMCPY(NULL, ...) crash). */
875+
ExpectNull(wolfSSL_get_shared_ciphers(ssl, NULL, sizeof(buf)));
876+
/* len == 0 - pre-existing guard; pins the contract. */
877+
ExpectNull(wolfSSL_get_shared_ciphers(ssl, buf, 0));
878+
879+
wolfSSL_free(ssl);
880+
wolfSSL_CTX_free(ctx);
881+
#endif /* NO_WOLFSSL_CLIENT */
882+
#endif
883+
return EXPECT_RESULT();
884+
}
885+

tests/api/test_tls.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int test_tls12_bad_cv_sig_alg(void);
3232
int test_tls12_no_null_compression(void);
3333
int test_tls12_etm_failed_resumption(void);
3434
int test_tls_set_curves_list_ecc_fallback(void);
35+
int test_wolfSSL_get_shared_ciphers(void);
3536

3637
#define TEST_TLS_DECLS \
3738
TEST_DECL_GROUP("tls", test_utils_memio_move_message), \
@@ -43,6 +44,7 @@ int test_tls_set_curves_list_ecc_fallback(void);
4344
TEST_DECL_GROUP("tls", test_tls12_bad_cv_sig_alg), \
4445
TEST_DECL_GROUP("tls", test_tls12_no_null_compression), \
4546
TEST_DECL_GROUP("tls", test_tls12_etm_failed_resumption), \
46-
TEST_DECL_GROUP("tls", test_tls_set_curves_list_ecc_fallback)
47+
TEST_DECL_GROUP("tls", test_tls_set_curves_list_ecc_fallback), \
48+
TEST_DECL_GROUP("tls", test_wolfSSL_get_shared_ciphers)
4749

4850
#endif /* TESTS_API_TEST_TLS_H */

tests/api/test_tls13.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ int test_tls13_apis(void)
587587
#endif
588588
ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups,
589589
WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
590+
ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, -1),
591+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
590592
ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
591593
WOLFSSL_SUCCESS);
592594
ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
@@ -614,6 +616,8 @@ int test_tls13_apis(void)
614616
#endif
615617
ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
616618
WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
619+
ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, -1),
620+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
617621
ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
618622
WOLFSSL_SUCCESS);
619623
ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
@@ -645,6 +649,10 @@ int test_tls13_apis(void)
645649
WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
646650
ExpectIntEQ(wolfSSL_set1_groups(clientSsl, too_many_groups,
647651
WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
652+
ExpectIntEQ(wolfSSL_CTX_set1_groups(clientCtx, NULL, 1),
653+
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
654+
ExpectIntEQ(wolfSSL_set1_groups(clientSsl, NULL, 1),
655+
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
648656
#endif
649657
#ifndef NO_WOLFSSL_CLIENT
650658
#ifndef WOLFSSL_NO_TLS12

0 commit comments

Comments
 (0)