From 2e7dfd518121f483f20c06ac58f0a6062b1c7e4a Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 5 Mar 2024 10:54:33 +0100 Subject: [PATCH] tls13: Remove unnecessary cast from size_t to uint32_t Signed-off-by: Ronald Cron --- library/ssl_tls13_generic.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/library/ssl_tls13_generic.c b/library/ssl_tls13_generic.c index eec2bb4b75..9fbd3ac276 100644 --- a/library/ssl_tls13_generic.c +++ b/library/ssl_tls13_generic.c @@ -1459,8 +1459,6 @@ int mbedtls_ssl_tls13_write_early_data_ext(mbedtls_ssl_context *ssl, int mbedtls_ssl_tls13_check_early_data_len(mbedtls_ssl_context *ssl, size_t early_data_len) { - uint32_t uint32_early_data_len = (uint32_t) early_data_len; - /* * This function should be called only while an handshake is in progress * and thus a session under negotiation. Add a sanity check to detect a @@ -1475,13 +1473,13 @@ int mbedtls_ssl_tls13_check_early_data_len(mbedtls_ssl_context *ssl, * A server receiving more than max_early_data_size bytes of 0-RTT data * SHOULD terminate the connection with an "unexpected_message" alert. */ - if (uint32_early_data_len > + if (early_data_len > (ssl->session_negotiate->max_early_data_size - ssl->total_early_data_size)) { MBEDTLS_SSL_DEBUG_MSG( - 2, ("EarlyData: Too much early data received, %u > %u", - ssl->total_early_data_size + uint32_early_data_len, + 2, ("EarlyData: Too much early data received, %u + %" MBEDTLS_PRINTF_SIZET " > %u", + ssl->total_early_data_size, early_data_len, ssl->session_negotiate->max_early_data_size)); MBEDTLS_SSL_PEND_FATAL_ALERT( @@ -1490,7 +1488,13 @@ int mbedtls_ssl_tls13_check_early_data_len(mbedtls_ssl_context *ssl, return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE; } - ssl->total_early_data_size += uint32_early_data_len; + /* + * The check just above implies that early_data_len is lower than + * UINT32_MAX thus its cast to an uint32_t below is safe. We need it + * to appease some compilers. + */ + + ssl->total_early_data_size += (uint32_t) early_data_len; return 0; }