mbedtls_asn1_store_named_data: clarify val allocation behavior
Document how mbedtls_asn1_store_named_data allocates val.p in the new or modified entry. Change the behavior to be more regular, always setting the new length to val_len. This does not affect the previous documented behavior since this aspect was not documented. This does not affect current usage in Mbed TLS's X.509 module where calls with the same OID always use the same size for the associated value.
This commit is contained in:
parent
a902303587
commit
09c0a2364b
2 changed files with 20 additions and 8 deletions
|
@ -432,18 +432,26 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(
|
|||
memcpy( cur->oid.p, oid, oid_len );
|
||||
|
||||
cur->val.len = val_len;
|
||||
cur->val.p = mbedtls_calloc( 1, val_len );
|
||||
if( cur->val.p == NULL )
|
||||
if( val_len != 0 )
|
||||
{
|
||||
mbedtls_free( cur->oid.p );
|
||||
mbedtls_free( cur );
|
||||
return( NULL );
|
||||
cur->val.p = mbedtls_calloc( 1, val_len );
|
||||
if( cur->val.p == NULL )
|
||||
{
|
||||
mbedtls_free( cur->oid.p );
|
||||
mbedtls_free( cur );
|
||||
return( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
cur->next = *head;
|
||||
*head = cur;
|
||||
}
|
||||
else if( cur->val.len < val_len )
|
||||
else if( val_len == 0 )
|
||||
{
|
||||
mbedtls_free( cur->val.p );
|
||||
cur->val.p = NULL;
|
||||
}
|
||||
else if( cur->val.len != val_len )
|
||||
{
|
||||
/*
|
||||
* Enlarge existing value buffer if needed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue