Skip to content

Commit de79d60

Browse files
committed
Strengthen regression tests for group and shared-cipher API guards
1 parent 47bdc04 commit de79d60

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

tests/api/test_tls.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,25 +1123,25 @@ int test_wolfSSL_alert_type_string(void)
11231123
int test_wolfSSL_get_shared_ciphers(void)
11241124
{
11251125
EXPECT_DECLS;
1126-
#if !defined(WOLFSSL_NO_TLS12) && !defined(NO_TLS)
1127-
#ifndef NO_WOLFSSL_CLIENT
1126+
#if !defined(NO_TLS) && !defined(NO_WOLFSSL_CLIENT)
11281127
WOLFSSL_CTX* ctx = NULL;
11291128
WOLFSSL* ssl = NULL;
11301129
char buf[32];
11311130

1132-
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
1131+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
11331132
ExpectNotNull(ssl = wolfSSL_new(ctx));
11341133

1135-
/* NULL ssl - pre-existing guard; pins the contract. */
11361134
ExpectNull(wolfSSL_get_shared_ciphers(NULL, buf, sizeof(buf)));
1137-
/* NULL buf - primary regression case (pre-fix: XMEMCPY(NULL, ...) crash). */
11381135
ExpectNull(wolfSSL_get_shared_ciphers(ssl, NULL, sizeof(buf)));
1139-
/* len == 0 - pre-existing guard; pins the contract. */
11401136
ExpectNull(wolfSSL_get_shared_ciphers(ssl, buf, 0));
1137+
#ifndef NO_ERROR_STRINGS
1138+
ExpectPtrEq(wolfSSL_get_shared_ciphers(ssl, buf, sizeof(buf)), buf);
1139+
#else
1140+
ExpectNull(wolfSSL_get_shared_ciphers(ssl, buf, sizeof(buf)));
1141+
#endif
11411142

11421143
wolfSSL_free(ssl);
11431144
wolfSSL_CTX_free(ctx);
1144-
#endif /* NO_WOLFSSL_CLIENT */
11451145
#endif
11461146
return EXPECT_RESULT();
11471147
}

tests/api/test_tls13.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,11 @@ 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));
592590
ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
593591
WOLFSSL_SUCCESS);
592+
ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, -1),
593+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
594+
ExpectIntEQ(clientCtx->numGroups, numGroups);
594595
ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
595596
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
596597
#endif
@@ -616,10 +617,11 @@ int test_tls13_apis(void)
616617
#endif
617618
ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
618619
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));
621620
ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
622621
WOLFSSL_SUCCESS);
622+
ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, -1),
623+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
624+
ExpectIntEQ(clientSsl->numGroups, numGroups);
623625
ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
624626
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
625627
#endif
@@ -653,6 +655,16 @@ int test_tls13_apis(void)
653655
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
654656
ExpectIntEQ(wolfSSL_set1_groups(clientSsl, NULL, 1),
655657
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
658+
ExpectIntEQ(wolfSSL_CTX_set1_groups(clientCtx, groups, numGroups),
659+
WOLFSSL_SUCCESS);
660+
ExpectIntEQ(wolfSSL_CTX_set1_groups(clientCtx, groups, -1),
661+
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
662+
ExpectIntEQ(clientCtx->numGroups, numGroups);
663+
ExpectIntEQ(wolfSSL_set1_groups(clientSsl, groups, numGroups),
664+
WOLFSSL_SUCCESS);
665+
ExpectIntEQ(wolfSSL_set1_groups(clientSsl, groups, -1),
666+
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
667+
ExpectIntEQ(clientSsl->numGroups, numGroups);
656668
#endif
657669
#ifndef NO_WOLFSSL_CLIENT
658670
#ifndef WOLFSSL_NO_TLS12

0 commit comments

Comments
 (0)