mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-29 12:32:48 +00:00
Correct the fix for the PKCS 7 memory leak
This corrects an issue in the origina fix in 4f01121f6e598c51e42a69f3fd9a54846013117a. Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
This commit is contained in:
parent
1362c5ab16
commit
f7641544ea
@ -253,6 +253,24 @@ static int pkcs7_get_signature( unsigned char **p, unsigned char *end,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void pkcs7_free_signer_info( mbedtls_pkcs7_signer_info *signer )
|
||||
{
|
||||
mbedtls_x509_name *name_cur;
|
||||
mbedtls_x509_name *name_prv;
|
||||
|
||||
if( signer == NULL )
|
||||
return;
|
||||
|
||||
name_cur = signer->issuer.next;
|
||||
while( name_cur != NULL )
|
||||
{
|
||||
name_prv = name_cur;
|
||||
name_cur = name_cur->next;
|
||||
mbedtls_free( name_prv );
|
||||
}
|
||||
signer->issuer.next = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* SignerInfo ::= SEQUENCE {
|
||||
* version Version;
|
||||
@ -329,33 +347,16 @@ static int pkcs7_get_signer_info( unsigned char **p, unsigned char *end,
|
||||
ret = MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO;
|
||||
|
||||
out:
|
||||
if( asn1_ret != 0 )
|
||||
if( asn1_ret != 0 || ret != 0 )
|
||||
{
|
||||
pkcs7_free_signer_info( signer );
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO,
|
||||
asn1_ret );
|
||||
else if( ret != 0 )
|
||||
ret = MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO;
|
||||
}
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
static void pkcs7_free_signer_info( mbedtls_pkcs7_signer_info *signer )
|
||||
{
|
||||
mbedtls_x509_name *name_cur;
|
||||
mbedtls_x509_name *name_prv;
|
||||
|
||||
if( signer == NULL )
|
||||
return;
|
||||
|
||||
name_cur = signer->issuer.next;
|
||||
while( name_cur != NULL )
|
||||
{
|
||||
name_prv = name_cur;
|
||||
name_cur = name_cur->next;
|
||||
mbedtls_free( name_prv );
|
||||
}
|
||||
signer->issuer.next = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* SignerInfos ::= SET of SignerInfo
|
||||
* Return number of signers added to the signed data,
|
||||
@ -387,7 +388,7 @@ static int pkcs7_get_signers_info_set( unsigned char **p, unsigned char *end,
|
||||
|
||||
ret = pkcs7_get_signer_info( p, end_set, signers_set );
|
||||
if( ret != 0 )
|
||||
goto cleanup;
|
||||
return( ret );
|
||||
count++;
|
||||
|
||||
mbedtls_pkcs7_signer_info *prev = signers_set;
|
||||
|
Loading…
x
Reference in New Issue
Block a user