mbedtls_asn1_get_int: allow leading zeros properly

Allow any number of leading zeros, not just based on sizeof(int).
This commit is contained in:
Gilles Peskine 2019-03-01 18:06:08 +01:00
parent 27d806fab4
commit f7d6acd475

View file

@ -149,11 +149,18 @@ int mbedtls_asn1_get_int( unsigned char **p,
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
return( ret );
if( len == 0 || len > sizeof( int ) || ( **p & 0x80 ) != 0 )
if( len == 0 || ( **p & 0x80 ) != 0 )
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
while( len > 0 && **p == 0 )
{
++( *p );
--len;
}
if( len > sizeof( int ) )
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
*val = 0;
while( len-- > 0 )
{
*val = ( *val << 8 ) | **p;