From 50f6a192b5a6ce05b66a438ec5e1a94c81d5f22d Mon Sep 17 00:00:00 2001 From: makise-homura Date: Sun, 23 Aug 2020 00:39:15 +0300 Subject: [PATCH 1/3] Backport e2k support to mbedtls-2.7 Covers commits ac2fd65, 0be6aa9, e74f372, e559550 from `development` branch Signed-off-by: makise-homura --- ChangeLog.d/e2k-support.txt | 5 +++++ library/ssl_tls.c | 4 ++-- tests/suites/helpers.function | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 ChangeLog.d/e2k-support.txt diff --git a/ChangeLog.d/e2k-support.txt b/ChangeLog.d/e2k-support.txt new file mode 100644 index 000000000..023b1888e --- /dev/null +++ b/ChangeLog.d/e2k-support.txt @@ -0,0 +1,5 @@ +Features + * Support building on e2k (Elbrus) architecture: correctly enable + -Wformat-signedness, and fix the code that causes signed-one-bit-field + and sign-compare warnings. Contributed by makise-homura (Igor Molchanov) + . diff --git a/library/ssl_tls.c b/library/ssl_tls.c index a40b46a1c..b82dec9b8 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2762,7 +2762,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( ret < 0 ) return( ret ); - if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && ret > SIZE_MAX ) ) + if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_recv returned %d bytes but only %lu were requested", @@ -2816,7 +2816,7 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl ) if( ret <= 0 ) return( ret ); - if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && ret > SIZE_MAX ) ) + if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_send returned %d bytes but only %lu bytes were sent", diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index 523db86e4..0c2724340 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -244,7 +244,7 @@ typedef enum /* A compile-time constant with the value 0. If `const_expr` is not a * compile-time constant with a nonzero value, cause a compile-time error. */ #define STATIC_ASSERT_EXPR( const_expr ) \ - ( 0 && sizeof( struct { int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) ) + ( 0 && sizeof( struct { unsigned int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) ) /* Return the scalar value `value` (possibly promoted). This is a compile-time * constant if `value` is. `condition` must be a compile-time constant. * If `condition` is false, arrange to cause a compile-time error. */ From 03b4ef6a05c0b87f0c1bb5880520204686c94b38 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Sat, 22 Aug 2020 23:56:46 +0300 Subject: [PATCH 2/3] Don't forget to free G, P, Q, ctr_drbg, and entropy I might be wrong, but lcc's optimizer is curious about this, and I am too: shouldn't we free allocated stuff correctly before exiting `dh_genprime` in this certain point of code? Signed-off-by: makise-homura --- programs/pkey/dh_genprime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index aefd6d608..2ccc63b6e 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -118,7 +118,7 @@ int main( int argc, char **argv ) { usage: mbedtls_printf( USAGE ); - mbedtls_exit( exit_code ); + goto exit; } for( i = 1; i < argc; i++ ) From 8c3fa63f90fd56c78ce935238dd1b3830c578822 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Mon, 24 Aug 2020 18:33:54 +0300 Subject: [PATCH 3/3] A different approach of signed-to-unsigned comparison Suggested by @hanno-arm Signed-off-by: makise-homura --- library/ssl_tls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index b82dec9b8..c2ae418cb 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2762,7 +2762,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want ) if( ret < 0 ) return( ret ); - if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) + if ( (size_t)ret > len || ( INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_recv returned %d bytes but only %lu were requested", @@ -2816,7 +2816,7 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl ) if( ret <= 0 ) return( ret ); - if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && (size_t)ret > SIZE_MAX ) ) + if( (size_t)ret > ssl->out_left || ( INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX ) ) { MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_send returned %d bytes but only %lu bytes were sent",