From 0efac53cdc9554eb532bc1b3644d940f6b4fb3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Fri, 4 Oct 2019 13:21:08 +0300 Subject: [PATCH] Review fixes: fixed comments to be more accurate and changed one memcmp to safer version --- library/ssl_tls.c | 10 +++++----- library/x509.c | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index ed14cb337..14747525c 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2883,7 +2883,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl, * Match record's CID with incoming CID. */ if( rec->cid_len != transform->in_cid_len || - memcmp( rec->cid, transform->in_cid, rec->cid_len ) != 0 ) // use regular memcmp as CID is not that critical + memcmp( rec->cid, transform->in_cid, rec->cid_len ) != 0 ) // use regular memcmp as CID is public { return( MBEDTLS_ERR_SSL_UNEXPECTED_CID ); } @@ -6013,7 +6013,7 @@ static int ssl_buffer_message( mbedtls_ssl_context *ssl ) else { /* Make sure msg_type and length are consistent */ - if( memcmp( hs_buf->data, ssl->in_msg, 4 ) != 0 ) // use regular memcmp as msg type is not that critical + if( memcmp( hs_buf->data, ssl->in_msg, 4 ) != 0 ) // use regular memcmp as msg type is public { MBEDTLS_SSL_DEBUG_MSG( 1, ( "Fragment header mismatch - ignore" ) ); /* Ignore */ @@ -7086,7 +7086,7 @@ static int ssl_srv_check_client_no_crt_notification( mbedtls_ssl_context *ssl ) if( ssl->in_hslen == 3 + mbedtls_ssl_hs_hdr_len( ssl ) && ssl->in_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE && ssl->in_msg[0] == MBEDTLS_SSL_HS_CERTIFICATE && - memcmp( ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ), "\0\0\0", 3 ) == 0 ) // use regular memcmp as this compare is not that critical + memcmp( ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ), "\0\0\0", 3 ) == 0 ) // use regular memcmp as comparing public data { MBEDTLS_SSL_DEBUG_MSG( 1, ( "TLSv1 client has no certificate" ) ); return( 0 ); @@ -9961,7 +9961,7 @@ static int ssl_session_load( mbedtls_ssl_session *session, if( (size_t)( end - p ) < sizeof( ssl_serialized_session_header ) ) return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); - // use regular memcmp as session header is not that critical + // use regular memcmp as session header is public data if( memcmp( p, ssl_serialized_session_header, sizeof( ssl_serialized_session_header ) ) != 0 ) { @@ -10404,7 +10404,7 @@ static int ssl_check_ctr_renegotiate( mbedtls_ssl_context *ssl ) return( 0 ); } - // use regular memcmp as counters are not that critical + // use regular memcmp as counters are public data in_ctr_cmp = memcmp( ssl->in_ctr + ep_len, ssl->conf->renego_period + ep_len, 8 - ep_len ); out_ctr_cmp = memcmp( ssl->cur_out_ctr + ep_len, diff --git a/library/x509.c b/library/x509.c index a79676095..1e61db8a4 100644 --- a/library/x509.c +++ b/library/x509.c @@ -588,9 +588,8 @@ int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a, if( ret != 0 ) goto exit; - // use regular memcmp as oid is not that critical if( oid[0].len != oid[1].len || - memcmp( oid[0].p, oid[1].p, oid[1].len ) != 0 ) + mbedtls_platform_memcmp( oid[0].p, oid[1].p, oid[1].len ) != 0 ) { return( 1 ); }