From 889bbc70b640a4ba4a663fb9c49c9d5af8038511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 18 Jun 2019 10:56:09 +0200 Subject: [PATCH] Fix unreachable code warnings with armc5 Some TLS-only code paths were not protected by an #ifdef and while some compiler are happy to just silently remove them, armc5 complains: Warning: #111-D: statement is unreachable Let's make armc5 happy. --- include/mbedtls/ssl_internal.h | 5 +++- library/ssl_tls.c | 47 +++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/include/mbedtls/ssl_internal.h b/include/mbedtls/ssl_internal.h index e6c829d3a..8089441c4 100644 --- a/include/mbedtls/ssl_internal.h +++ b/include/mbedtls/ssl_internal.h @@ -969,8 +969,11 @@ static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl ) #if defined(MBEDTLS_SSL_PROTO_DTLS) if( MBEDTLS_SSL_TRANSPORT_IS_DTLS( ssl->conf->transport ) ) return( 12 ); + MBEDTLS_SSL_TRANSPORT_ELSE +#endif +#if defined(MBEDTLS_SSL_PROTO_TLS) + return( 4 ); #endif - return( 4 ); } #if defined(MBEDTLS_SSL_PROTO_DTLS) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index e3ce5908f..912fdec80 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -68,8 +68,11 @@ static inline size_t ssl_ep_len( const mbedtls_ssl_context *ssl ) #if defined(MBEDTLS_SSL_PROTO_DTLS) if( MBEDTLS_SSL_TRANSPORT_IS_DTLS( ssl->conf->transport ) ) return( 2 ); + MBEDTLS_SSL_TRANSPORT_ELSE #endif +#if defined(MBEDTLS_SSL_PROTO_TLS) return( 0 ); +#endif } /* @@ -8598,25 +8601,29 @@ const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl ) return( "unknown (DTLS)" ); } } -#endif - - switch( ssl->minor_ver ) + MBEDTLS_SSL_TRANSPORT_ELSE +#endif /* MBEDTLS_SSL_PROTO_DTLS */ +#if defined(MBEDTLS_SSL_PROTO_TLS) { - case MBEDTLS_SSL_MINOR_VERSION_0: - return( "SSLv3.0" ); + switch( ssl->minor_ver ) + { + case MBEDTLS_SSL_MINOR_VERSION_0: + return( "SSLv3.0" ); - case MBEDTLS_SSL_MINOR_VERSION_1: - return( "TLSv1.0" ); + case MBEDTLS_SSL_MINOR_VERSION_1: + return( "TLSv1.0" ); - case MBEDTLS_SSL_MINOR_VERSION_2: - return( "TLSv1.1" ); + case MBEDTLS_SSL_MINOR_VERSION_2: + return( "TLSv1.1" ); - case MBEDTLS_SSL_MINOR_VERSION_3: - return( "TLSv1.2" ); + case MBEDTLS_SSL_MINOR_VERSION_3: + return( "TLSv1.2" ); - default: - return( "unknown" ); + default: + return( "unknown" ); + } } +#endif /* MBEDTLS_SSL_PROTO_TLS */ } int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl ) @@ -9610,8 +9617,13 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) { continue; } + MBEDTLS_SSL_TRANSPORT_ELSE +#endif +#if defined(MBEDTLS_SSL_PROTO_TLS) + { + return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + } #endif - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); } #endif /* MBEDTLS_SSL_CLI_C */ @@ -9627,8 +9639,13 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ) { continue; } + MBEDTLS_SSL_TRANSPORT_ELSE +#endif +#if defined(MBEDTLS_SSL_PROTO_TLS) + { + return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); + } #endif - return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE ); } #endif /* MBEDTLS_SSL_SRV_C */