mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 13:25:28 +00:00
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:
parent
27d806fab4
commit
f7d6acd475
|
@ -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 )
|
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
|
||||||
return( ret );
|
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 );
|
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||||
|
|
||||||
*val = 0;
|
*val = 0;
|
||||||
|
|
||||||
while( len-- > 0 )
|
while( len-- > 0 )
|
||||||
{
|
{
|
||||||
*val = ( *val << 8 ) | **p;
|
*val = ( *val << 8 ) | **p;
|
||||||
|
|
Loading…
Reference in a new issue