mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Correct the fix for the PKCS 7 memory leak
This corrects an issue in the origina fix in
4f01121f6e
.
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
This commit is contained in:
@@ -253,6 +253,24 @@ static int pkcs7_get_signature( unsigned char **p, unsigned char *end,
|
|||||||
return( 0 );
|
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 {
|
* SignerInfo ::= SEQUENCE {
|
||||||
* version Version;
|
* 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;
|
ret = MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO;
|
||||||
|
|
||||||
out:
|
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,
|
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO,
|
||||||
asn1_ret );
|
asn1_ret );
|
||||||
else if( ret != 0 )
|
}
|
||||||
ret = MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO;
|
|
||||||
|
|
||||||
return( ret );
|
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
|
* SignerInfos ::= SET of SignerInfo
|
||||||
* Return number of signers added to the signed data,
|
* 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 );
|
ret = pkcs7_get_signer_info( p, end_set, signers_set );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
goto cleanup;
|
return( ret );
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
mbedtls_pkcs7_signer_info *prev = signers_set;
|
mbedtls_pkcs7_signer_info *prev = signers_set;
|
||||||
|
Reference in New Issue
Block a user