Skip to content

Commit 428030a

Browse files
committed
Fix wolfSSL_get_ciphers_compat to return NULL when no ciphers available
1 parent aa9ee8b commit 428030a

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/ssl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16098,6 +16098,12 @@ WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1609816098
break;
1609916099
}
1610016100
}
16101+
16102+
/* If no ciphers were added, free empty stack and return NULL */
16103+
if (ssl->suitesStack != NULL && wolfSSL_sk_num(ssl->suitesStack) == 0) {
16104+
wolfSSL_sk_CIPHER_free(ssl->suitesStack);
16105+
((WOLFSSL*)ssl)->suitesStack = NULL;
16106+
}
1610116107
}
1610216108
return ssl->suitesStack;
1610316109
}

tests/api.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19272,6 +19272,39 @@ static int test_wolfSSL_get_ciphers_compat(void)
1927219272
return EXPECT_RESULT();
1927319273
}
1927419274

19275+
/* Test that wolfSSL_get_ciphers_compat returns NULL (not an empty stack)
19276+
* when no ciphers are available for a given protocol configuration.
19277+
* wolfSSL_get_ciphers_compat() is mapped to SSL_get_ciphers(), which has
19278+
* an expected return of NULL when no ciphers are available. */
19279+
static int test_wolfSSL_get_ciphers_compat_empty(void)
19280+
{
19281+
EXPECT_DECLS;
19282+
#if !defined(NO_TLS) && !defined(NO_WOLFSSL_CLIENT)
19283+
const SSL_METHOD *method = NULL;
19284+
SSL_CTX *ctx = NULL;
19285+
WOLFSSL *ssl = NULL;
19286+
STACK_OF(SSL_CIPHER) *ciphers = NULL;
19287+
19288+
ExpectNotNull(method = SSLv23_client_method());
19289+
ExpectNotNull(ctx = SSL_CTX_new(method));
19290+
ExpectNotNull(ssl = SSL_new(ctx));
19291+
19292+
/* Disable all protocol versions via options mask so that
19293+
* sslCipherMinMaxCheck filters out every cipher suite */
19294+
wolfSSL_set_options(ssl, SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 |
19295+
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3);
19296+
19297+
ciphers = wolfSSL_get_ciphers_compat(ssl);
19298+
19299+
/* Must be NULL, not a non-NULL empty stack */
19300+
ExpectNull(ciphers);
19301+
19302+
SSL_free(ssl);
19303+
SSL_CTX_free(ctx);
19304+
#endif
19305+
return EXPECT_RESULT();
19306+
}
19307+
1927519308
static int test_wolfSSL_CTX_ctrl(void)
1927619309
{
1927719310
EXPECT_DECLS;
@@ -34136,6 +34169,7 @@ TEST_CASE testCases[] = {
3413634169
#ifdef OPENSSL_ALL
3413734170
TEST_DECL(test_wolfSSL_sk_CIPHER_description),
3413834171
TEST_DECL(test_wolfSSL_get_ciphers_compat),
34172+
TEST_DECL(test_wolfSSL_get_ciphers_compat_empty),
3413934173

3414034174
TEST_DECL(test_wolfSSL_CTX_ctrl),
3414134175
#endif /* OPENSSL_ALL */

0 commit comments

Comments
 (0)