mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 07:35:42 +01:00
Add buffer length tests for mbedtls_asn1_write_len()
This commit is contained in:
parent
e325db9055
commit
58bfb83bb0
@ -50,22 +50,31 @@ ASN.1 Write IA5 String #5 (Buffer too small for string)
|
||||
mbedtls_asn1_write_ia5_string:"ABC":"":2:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ASN.1 Write / Read Length #0 (Len = 0, short form)
|
||||
mbedtls_asn1_write_len:0:"00":1
|
||||
mbedtls_asn1_write_len:0:"00":1:1
|
||||
|
||||
ASN.1 Write / Read Length #1 (Len = 127, short form)
|
||||
mbedtls_asn1_write_len:127:"7F":1
|
||||
mbedtls_asn1_write_len:127:"7F":1:1
|
||||
|
||||
ASN.1 Write / Read Length #2 (Len = 128, long form)
|
||||
mbedtls_asn1_write_len:128:"8180":2
|
||||
ASN.1 Write / Read Length #2 (Len = 127, buffer too small)
|
||||
mbedtls_asn1_write_len:127:"7F":0:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ASN.1 Write / Read Length #3 (Len = 255, long form)
|
||||
mbedtls_asn1_write_len:255:"81FF":2
|
||||
ASN.1 Write / Read Length #3 (Len = 128, long form)
|
||||
mbedtls_asn1_write_len:128:"8180":2:2
|
||||
|
||||
ASN.1 Write / Read Length #4 (Len = 256, long form)
|
||||
mbedtls_asn1_write_len:256:"820100":3
|
||||
ASN.1 Write / Read Length #4 (Len = 255, long form)
|
||||
mbedtls_asn1_write_len:255:"81FF":2:2
|
||||
|
||||
ASN.1 Write / Read Length #5 (Len = 65535, max supported length)
|
||||
mbedtls_asn1_write_len:65535:"82FFFF":3
|
||||
ASN.1 Write / Read Length #5 (Len = 255, buffer too small)
|
||||
mbedtls_asn1_write_len:255:"81FF":1:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ASN.1 Write / Read Length #6 (Len = 65536, not supported)
|
||||
mbedtls_asn1_write_len:65536:"":MBEDTLS_ERR_ASN1_INVALID_LENGTH
|
||||
ASN.1 Write / Read Length #6 (Len = 256, long form)
|
||||
mbedtls_asn1_write_len:256:"820100":3:3
|
||||
|
||||
ASN.1 Write / Read Length #7 (Len = 65535, max supported length)
|
||||
mbedtls_asn1_write_len:65535:"82FFFF":3:3
|
||||
|
||||
ASN.1 Write / Read Length #8 (Len = 65535, buffer too small)
|
||||
mbedtls_asn1_write_len:65535:"82FFFF":2:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ASN.1 Write / Read Length #9 (Len = 65536, not supported)
|
||||
mbedtls_asn1_write_len:65536:"":0:MBEDTLS_ERR_ASN1_INVALID_LENGTH
|
||||
|
@ -84,7 +84,8 @@ void mbedtls_asn1_write_ia5_string( char *str, char *hex_asn1,
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_asn1_write_len( int len, char *check_str, int result )
|
||||
void mbedtls_asn1_write_len( int len, char *check_str, int buf_len,
|
||||
int result )
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[150];
|
||||
@ -96,7 +97,7 @@ void mbedtls_asn1_write_len( int len, char *check_str, int result )
|
||||
memset( asn1, 0, sizeof( asn1 ) );
|
||||
asn1_len = unhexify( asn1, check_str );
|
||||
|
||||
p = buf + GUARD_LEN + asn1_len;
|
||||
p = buf + GUARD_LEN + buf_len;
|
||||
|
||||
ret = mbedtls_asn1_write_len( &p, buf + GUARD_LEN, (size_t) len );
|
||||
|
||||
@ -106,13 +107,13 @@ void mbedtls_asn1_write_len( int len, char *check_str, int result )
|
||||
for( i = 0; i < GUARD_LEN; i++ )
|
||||
{
|
||||
TEST_ASSERT( buf[i] == GUARD_VAL );
|
||||
TEST_ASSERT( buf[GUARD_LEN + asn1_len + i] == GUARD_VAL );
|
||||
TEST_ASSERT( buf[GUARD_LEN + buf_len + i] == GUARD_VAL );
|
||||
}
|
||||
|
||||
if( result >= 0 )
|
||||
{
|
||||
TEST_ASSERT( (size_t) ret == asn1_len );
|
||||
TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + asn1_len );
|
||||
TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + buf_len );
|
||||
|
||||
TEST_ASSERT( memcmp( p, asn1, asn1_len ) == 0 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user