From 4556d205a3bf5cc5e1ff44eb60d3ee891ac23322 Mon Sep 17 00:00:00 2001 From: Brian J Murray Date: Thu, 23 Jun 2016 12:57:03 -0700 Subject: [PATCH] Fixed unchecked calls to mbedtls_md_setup in rsa.c (#502) * Fixed unchecked calls to mbedtls_md_setup in rsa.c: * style fixes --- library/rsa.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/library/rsa.c b/library/rsa.c index 26d69c522..a025a0fb0 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -549,7 +549,11 @@ int rsa_rsaes_oaep_encrypt( rsa_context *ctx, memcpy( p, input, ilen ); md_init( &md_ctx ); - md_init_ctx( &md_ctx, md_info ); + if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 ) + { + md_free( &md_ctx ); + return( ret ); + } // maskedDB: Apply dbMask to DB // @@ -730,7 +734,11 @@ int rsa_rsaes_oaep_decrypt( rsa_context *ctx, return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); md_init( &md_ctx ); - md_init_ctx( &md_ctx, md_info ); + if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 ) + { + md_free( &md_ctx ); + return( ret ); + } /* Generate lHash */ md( md_info, label, label_len, lhash ); @@ -976,7 +984,11 @@ int rsa_rsassa_pss_sign( rsa_context *ctx, p += slen; md_init( &md_ctx ); - md_init_ctx( &md_ctx, md_info ); + if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 ) + { + md_free( &md_ctx ); + return( ret ); + } // Generate H = Hash( M' ) // @@ -1249,7 +1261,11 @@ int rsa_rsassa_pss_verify_ext( rsa_context *ctx, return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); md_init( &md_ctx ); - md_init_ctx( &md_ctx, md_info ); + if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 ) + { + md_free( &md_ctx ); + return( ret ); + } mgf_mask( p, siglen - hlen - 1, p + siglen - hlen - 1, hlen, &md_ctx );