Silence a clang-analyze warning

The check is already effectively performed later in the function, but
implicitly, so Clang's analysis fail to notice the functions are in
fact safe.  Pulling the check up to the top helps Clang to verify the
behaviour.
This commit is contained in:
Nicholas Wilson 2016-04-13 11:53:27 +01:00
parent 5d5e421d08
commit 42d47f0fb5

View File

@ -104,7 +104,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
/*
* Check for valid input
*/
if( csr == NULL || buf == NULL )
if( csr == NULL || buf == NULL || buflen == 0 )
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
mbedtls_x509_csr_init( csr );
@ -274,14 +274,14 @@ int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, siz
/*
* Check for valid input
*/
if( csr == NULL || buf == NULL )
if( csr == NULL || buf == NULL || buflen == 0 )
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
#if defined(MBEDTLS_PEM_PARSE_C)
mbedtls_pem_init( &pem );
/* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
if( buflen == 0 || buf[buflen - 1] != '\0' )
if( buf[buflen - 1] != '\0' )
ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
else
ret = mbedtls_pem_read_buffer( &pem,