Skip to content

Commit 6023975

Browse files
committed
Avoid memory leak when RSA-CRT is not enabled in build
1 parent 8c2631b commit 6023975

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/pkparse.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
769769
goto cleanup;
770770
p += len;
771771

772+
#if !defined(MBEDTLS_RSA_NO_CRT)
772773
/*
773774
* The RSA CRT parameters DP, DQ and QP are nominally redundant, in
774775
* that they can be easily recomputed from D, P and Q. However by
@@ -800,6 +801,13 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
800801
( ret = mbedtls_mpi_read_binary( &rsa->QP, p, len ) ) != 0 )
801802
goto cleanup;
802803
p += len;
804+
#else
805+
/* Verify existance of the CRT params */
806+
if( ( ret = mbedtls_asn1_get_mpi( &p, end, &T ) ) != 0 ||
807+
( ret = mbedtls_asn1_get_mpi( &p, end, &T ) ) != 0 ||
808+
( ret = mbedtls_asn1_get_mpi( &p, end, &T ) ) != 0 )
809+
goto cleanup;
810+
#endif
803811

804812
/* Complete the RSA private key */
805813
if( ( ret = mbedtls_rsa_complete( rsa ) ) != 0 )

0 commit comments

Comments
 (0)