Skip to content

Commit f33dfb9

Browse files
committed
extmod/modssl_mbedtls: Fix parsing of ciphers in set_ciphers method.
Fixes two issues: - None should not be allowed in the list, otherwise the corresponding entry in ciphersuites[i] will have an undefined value. - The terminating 0 needs to be put in ciphersuites[len]. Signed-off-by: Damien George <damien@micropython.org>
1 parent bba8a67 commit f33dfb9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

extmod/modssl_mbedtls.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,15 @@ STATIC mp_obj_t ssl_context_set_ciphers(mp_obj_t self_in, mp_obj_t ciphersuite)
294294

295295
// Parse list of ciphers.
296296
ssl_context->ciphersuites = m_new(int, len + 1);
297-
for (int i = 0, n = len; i < n; i++) {
298-
if (ciphers[i] != mp_const_none) {
299-
const char *ciphername = mp_obj_str_get_str(ciphers[i]);
300-
const int id = mbedtls_ssl_get_ciphersuite_id(ciphername);
301-
ssl_context->ciphersuites[i] = id;
302-
if (id == 0) {
303-
mbedtls_raise_error(MBEDTLS_ERR_SSL_BAD_CONFIG);
304-
}
297+
for (size_t i = 0; i < len; ++i) {
298+
const char *ciphername = mp_obj_str_get_str(ciphers[i]);
299+
const int id = mbedtls_ssl_get_ciphersuite_id(ciphername);
300+
if (id == 0) {
301+
mbedtls_raise_error(MBEDTLS_ERR_SSL_BAD_CONFIG);
305302
}
303+
ssl_context->ciphersuites[i] = id;
306304
}
307-
ssl_context->ciphersuites[len + 1] = 0;
305+
ssl_context->ciphersuites[len] = 0;
308306

309307
// Configure ciphersuite.
310308
mbedtls_ssl_conf_ciphersuites(&ssl_context->conf, (const int *)ssl_context->ciphersuites);

0 commit comments

Comments
 (0)