1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-04-21 23:05:55 +03:00

Merge pull request #6066 from AndrzejKurek/fix-some-resource-leaks-2-28

Fix `mbedtls_pk_parse_public_key` resource leaks
This commit is contained in:
Paul Elliott 2022-07-05 23:12:11 +01:00 committed by GitHub
commit 06986de4ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Bugfix
* Fix resource leaks in mbedtls_pk_parse_public_key() in low
memory conditions.

View File

@ -1463,10 +1463,16 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
{ {
p = pem.buf; p = pem.buf;
if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL )
{
mbedtls_pem_free( &pem );
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
}
if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 ) if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 )
{
mbedtls_pem_free( &pem );
return( ret ); return( ret );
}
if ( ( ret = pk_get_rsapubkey( &p, p + pem.buflen, mbedtls_pk_rsa( *ctx ) ) ) != 0 ) if ( ( ret = pk_get_rsapubkey( &p, p + pem.buflen, mbedtls_pk_rsa( *ctx ) ) ) != 0 )
mbedtls_pk_free( ctx ); mbedtls_pk_free( ctx );