From ecfaeaddb3e4542ae39afefed09c91cf58656449 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 24 Mar 2026 00:22:29 +0530 Subject: [PATCH] Fix unused function warning commit 4ac4008fa0 ("Access ssl->hostname through abstractions in certificate verification"). Due to this an unused function warning can occur if neither SNI nor handshake is enabled. Signed-off-by: Chaitanya Tata --- library/ssl_tls.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 1185b0b283..88aaf85d29 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2803,8 +2803,14 @@ static int mbedtls_ssl_has_set_hostname_been_called( } #endif -/* Micro-optimization: don't export this function if it isn't needed outside - * of this source file. */ +/* + * Exported for ssl_client.c when SNI is enabled. When SNI is off the only + * in-file caller is get_hostname_for_verification() which is guarded by + * MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED, so compile the function out + * entirely when neither macro is defined. + */ +#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) || \ + defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) #if !defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) static #endif @@ -2815,6 +2821,7 @@ const char *mbedtls_ssl_get_hostname_pointer(const mbedtls_ssl_context *ssl) } return ssl->hostname; } +#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION || MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */ static void mbedtls_ssl_free_hostname(mbedtls_ssl_context *ssl) {