Fix possible memory leak in <MD>_ext()

This commit is contained in:
Andres Amaya Garcia 2017-07-20 14:34:08 +01:00
parent 94682d1d7d
commit 0963e6cfac
7 changed files with 35 additions and 29 deletions

View file

@ -229,18 +229,18 @@ int mbedtls_md2_ext( const unsigned char *input,
mbedtls_md2_init( &ctx ); mbedtls_md2_init( &ctx );
if( ( ret = mbedtls_md2_starts_ext( &ctx ) ) != 0 ) if( ( ret = mbedtls_md2_starts_ext( &ctx ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_md2_update_ext( &ctx, input, ilen ) ) != 0 ) if( ( ret = mbedtls_md2_update_ext( &ctx, input, ilen ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_md2_finish_ext( &ctx, output ) ) != 0 ) if( ( ret = mbedtls_md2_finish_ext( &ctx, output ) ) != 0 )
return( ret ); goto exit;
exit:
mbedtls_md2_free( &ctx ); mbedtls_md2_free( &ctx );
return( 0 ); return( ret );
} }
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)

View file

@ -333,17 +333,18 @@ int mbedtls_md4_ext( const unsigned char *input,
mbedtls_md4_init( &ctx ); mbedtls_md4_init( &ctx );
if( ( ret = mbedtls_md4_starts_ext( &ctx ) ) != 0 ) if( ( ret = mbedtls_md4_starts_ext( &ctx ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_md4_update_ext( &ctx, input, ilen ) ) != 0 ) if( ( ret = mbedtls_md4_update_ext( &ctx, input, ilen ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_md4_finish_ext( &ctx, output ) ) != 0 ) if( ( ret = mbedtls_md4_finish_ext( &ctx, output ) ) != 0 )
return( ret ); goto exit;
exit:
mbedtls_md4_free( &ctx ); mbedtls_md4_free( &ctx );
return( 0 ); return( ret );
} }
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)

View file

@ -347,17 +347,18 @@ int mbedtls_md5_ext( const unsigned char *input,
mbedtls_md5_init( &ctx ); mbedtls_md5_init( &ctx );
if( ( ret = mbedtls_md5_starts_ext( &ctx ) ) != 0 ) if( ( ret = mbedtls_md5_starts_ext( &ctx ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_md5_update_ext( &ctx, input, ilen ) ) != 0 ) if( ( ret = mbedtls_md5_update_ext( &ctx, input, ilen ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_md5_finish_ext( &ctx, output ) ) != 0 ) if( ( ret = mbedtls_md5_finish_ext( &ctx, output ) ) != 0 )
return( ret ); goto exit;
exit:
mbedtls_md5_free( &ctx ); mbedtls_md5_free( &ctx );
return( 0 ); return( ret );
} }
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)

View file

@ -406,17 +406,18 @@ int mbedtls_ripemd160_ext( const unsigned char *input,
mbedtls_ripemd160_init( &ctx ); mbedtls_ripemd160_init( &ctx );
if( ( ret = mbedtls_ripemd160_starts_ext( &ctx ) ) != 0 ) if( ( ret = mbedtls_ripemd160_starts_ext( &ctx ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_ripemd160_update_ext( &ctx, input, ilen ) ) != 0 ) if( ( ret = mbedtls_ripemd160_update_ext( &ctx, input, ilen ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_ripemd160_finish_ext( &ctx, output ) ) != 0 ) if( ( ret = mbedtls_ripemd160_finish_ext( &ctx, output ) ) != 0 )
return( ret ); goto exit;
exit:
mbedtls_ripemd160_free( &ctx ); mbedtls_ripemd160_free( &ctx );
return( 0 ); return( ret );
} }
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)

View file

@ -380,17 +380,18 @@ int mbedtls_sha1_ext( const unsigned char *input,
mbedtls_sha1_init( &ctx ); mbedtls_sha1_init( &ctx );
if( ( ret = mbedtls_sha1_starts_ext( &ctx ) ) != 0 ) if( ( ret = mbedtls_sha1_starts_ext( &ctx ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_sha1_update_ext( &ctx, input, ilen ) ) != 0 ) if( ( ret = mbedtls_sha1_update_ext( &ctx, input, ilen ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_sha1_finish_ext( &ctx, output ) ) != 0 ) if( ( ret = mbedtls_sha1_finish_ext( &ctx, output ) ) != 0 )
return( ret ); goto exit;
exit:
mbedtls_sha1_free( &ctx ); mbedtls_sha1_free( &ctx );
return( 0 ); return( ret );
} }
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)

View file

@ -355,17 +355,18 @@ int mbedtls_sha256_ext( const unsigned char *input,
mbedtls_sha256_init( &ctx ); mbedtls_sha256_init( &ctx );
if( ( ret = mbedtls_sha256_starts_ext( &ctx, is224 ) ) != 0 ) if( ( ret = mbedtls_sha256_starts_ext( &ctx, is224 ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_sha256_update_ext( &ctx, input, ilen ) ) != 0 ) if( ( ret = mbedtls_sha256_update_ext( &ctx, input, ilen ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_sha256_finish_ext( &ctx, output ) ) != 0 ) if( ( ret = mbedtls_sha256_finish_ext( &ctx, output ) ) != 0 )
return( ret ); goto exit;
exit:
mbedtls_sha256_free( &ctx ); mbedtls_sha256_free( &ctx );
return( 0 ); return( ret );
} }
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)

View file

@ -391,17 +391,18 @@ int mbedtls_sha512_ext( const unsigned char *input,
mbedtls_sha512_init( &ctx ); mbedtls_sha512_init( &ctx );
if( ( ret = mbedtls_sha512_starts_ext( &ctx, is384 ) ) != 0 ) if( ( ret = mbedtls_sha512_starts_ext( &ctx, is384 ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_sha512_update_ext( &ctx, input, ilen ) ) != 0 ) if( ( ret = mbedtls_sha512_update_ext( &ctx, input, ilen ) ) != 0 )
return( ret ); goto exit;
if( ( ret = mbedtls_sha512_finish_ext( &ctx, output ) ) != 0 ) if( ( ret = mbedtls_sha512_finish_ext( &ctx, output ) ) != 0 )
return( ret ); goto exit;
exit:
mbedtls_sha512_free( &ctx ); mbedtls_sha512_free( &ctx );
return( 0 ); return( ret );
} }
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)