mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 08:45:27 +00:00
Fix dual use of buffer in test
x509_get_name() does not make defensive copies of strings in its input (which is OK as usually the caller will have made a copy already), so we shouldn't reuse its input buffer as an output while "parsed" is still alive.
This commit is contained in:
parent
4b00f08e20
commit
4fd0b256a8
|
@ -140,9 +140,10 @@ void mbedtls_x509_string_to_names( char *name, char *parsed_name, int result )
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
mbedtls_asn1_named_data *names = NULL;
|
mbedtls_asn1_named_data *names = NULL;
|
||||||
mbedtls_x509_name parsed, *parsed_cur, *parsed_prv;
|
mbedtls_x509_name parsed, *parsed_cur, *parsed_prv;
|
||||||
unsigned char buf[2048], *c;
|
unsigned char buf[1024], out[1024], *c;
|
||||||
|
|
||||||
memset( &parsed, 0, sizeof( parsed ) );
|
memset( &parsed, 0, sizeof( parsed ) );
|
||||||
|
memset( out, 0, sizeof( out ) );
|
||||||
memset( buf, 0, sizeof( buf ) );
|
memset( buf, 0, sizeof( buf ) );
|
||||||
c = buf + sizeof( buf );
|
c = buf + sizeof( buf );
|
||||||
|
|
||||||
|
@ -159,10 +160,10 @@ void mbedtls_x509_string_to_names( char *name, char *parsed_name, int result )
|
||||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) == 0 );
|
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) == 0 );
|
||||||
TEST_ASSERT( mbedtls_x509_get_name( &c, buf + sizeof( buf ), &parsed ) == 0 );
|
TEST_ASSERT( mbedtls_x509_get_name( &c, buf + sizeof( buf ), &parsed ) == 0 );
|
||||||
|
|
||||||
ret = mbedtls_x509_dn_gets( (char *) buf, sizeof( buf ), &parsed );
|
ret = mbedtls_x509_dn_gets( (char *) out, sizeof( out ), &parsed );
|
||||||
TEST_ASSERT( ret > 0 );
|
TEST_ASSERT( ret > 0 );
|
||||||
|
|
||||||
TEST_ASSERT( strcmp( (char *) buf, parsed_name ) == 0 );
|
TEST_ASSERT( strcmp( (char *) out, parsed_name ) == 0 );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_asn1_free_named_data_list( &names );
|
mbedtls_asn1_free_named_data_list( &names );
|
||||||
|
|
Loading…
Reference in a new issue