From d7adc374d325dea0647e0c0c99b1270046116f90 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Tue, 11 Oct 2022 09:05:11 +0000 Subject: [PATCH] Refine the server name compare logic Signed-off-by: Xiaokang Qian --- library/ssl_client.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/library/ssl_client.c b/library/ssl_client.c index 993539573..48a19c9e4 100644 --- a/library/ssl_client.c +++ b/library/ssl_client.c @@ -876,19 +876,11 @@ static int ssl_prepare_client_hello( mbedtls_ssl_context *ssl ) if( ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_3 && ssl->handshake->resume ) { - int hostname_mismatch = 0; - if( ssl->session_negotiate->hostname != NULL ) - { - if( ssl->hostname != NULL ) - { - if( strcmp( ssl->hostname, ssl->session_negotiate->hostname) ) - hostname_mismatch = 1; - } - else - hostname_mismatch = 1; - } - else - hostname_mismatch = ssl->hostname != NULL; + int hostname_mismatch = ssl->hostname != NULL || + ssl->session_negotiate->hostname != NULL; + if( ssl->hostname != NULL && ssl->session_negotiate->hostname != NULL ) + hostname_mismatch = strcmp( + ssl->hostname, ssl->session_negotiate->hostname ) != 0; if( hostname_mismatch ) {