mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Add mbedtls_x509_get_name memory leak unit test
Introduce a unit test to test mbedtls_x509_get_name() and add a testcase with a corrupt DER-encoded name that causes mbedtls_x509_get_name() to have to cleanup things it is allocated. If it fails to do this, a memory leak is detected under Asan builds. Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
@ -818,6 +818,42 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
|
||||
void mbedtls_x509_get_name( char * hex_name, int exp_ret )
|
||||
{
|
||||
unsigned char *name;
|
||||
unsigned char *p;
|
||||
size_t name_len;
|
||||
mbedtls_x509_name head;
|
||||
mbedtls_x509_name *allocated, *prev;
|
||||
int res;
|
||||
|
||||
name = mbedtls_test_unhexify_alloc( hex_name, &name_len );
|
||||
p = name;
|
||||
|
||||
res = mbedtls_x509_get_name( &p, ( name + name_len ), &head );
|
||||
|
||||
if( res == 0 )
|
||||
{
|
||||
allocated = head.next;
|
||||
head.next = NULL;
|
||||
prev = NULL;
|
||||
|
||||
while( allocated != NULL )
|
||||
{
|
||||
prev = allocated;
|
||||
allocated = allocated->next;
|
||||
|
||||
mbedtls_free( prev );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_ASSERT( res == exp_ret );
|
||||
|
||||
mbedtls_free( name );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CREATE_C:MBEDTLS_X509_USE_C:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
|
||||
void mbedtls_x509_dn_get_next( char * name_str, int next_merged, char * expected_oids, int exp_count, char * exp_dn_gets )
|
||||
{
|
||||
|
Reference in New Issue
Block a user