1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

Fix use of pem_read_buffer() in PK, DHM and X509

This commit is contained in:
Manuel Pégourié-Gonnard
2015-05-12 11:20:10 +02:00
parent 2088ba6d30
commit 43b37cbc92
13 changed files with 112 additions and 46 deletions

View File

@ -503,6 +503,11 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s
do
{
mbedtls_pem_init( &pem );
/* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
if( buf[buflen - 1] != '\0' )
ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
else
ret = mbedtls_pem_read_buffer( &pem,
"-----BEGIN X509 CRL-----",
"-----END X509 CRL-----",
@ -532,7 +537,9 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s
return( ret );
}
}
while( is_pem && buflen > 0 );
/* In the PEM case, buflen is 1 at the end, for the terminated NULL byte.
* And a valid CRL cannot be less than 1 byte anyway. */
while( is_pem && buflen > 1 );
if( is_pem )
return( 0 );
@ -556,7 +563,7 @@ int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path )
ret = mbedtls_x509_crl_parse( chain, buf, n );
mbedtls_zeroize( buf, n + 1 );
mbedtls_zeroize( buf, n );
mbedtls_free( buf );
return( ret );