mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Introduce proper memory management for SANs
DirectoryName parsing performs allocation that has to be handled. Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
@ -1283,6 +1283,7 @@ int mbedtls_x509_get_subject_alt_name(unsigned char **p,
|
||||
return ret;
|
||||
}
|
||||
|
||||
mbedtls_x509_free_subject_alt_name(&dummy_san_buf);
|
||||
/* Allocate and assign next pointer */
|
||||
if (cur->buf.p != NULL) {
|
||||
if (cur->next != NULL) {
|
||||
@ -1467,6 +1468,13 @@ int mbedtls_x509_parse_subject_alt_name(const mbedtls_x509_buf *san_buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mbedtls_x509_free_subject_alt_name(mbedtls_x509_subject_alternative_name *san)
|
||||
{
|
||||
if (san->type == MBEDTLS_X509_SAN_DIRECTORY_NAME) {
|
||||
mbedtls_asn1_free_named_data_list_shallow(san->san.directory_name.next);
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
|
||||
const mbedtls_x509_sequence
|
||||
@ -1586,6 +1594,7 @@ int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
|
||||
ret = mbedtls_snprintf(p, n, "\n%s directoryName : ", prefix);
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
ret = mbedtls_x509_dn_gets(p, n, &san.san.directory_name);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -1603,6 +1612,9 @@ int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
|
||||
break;
|
||||
}
|
||||
|
||||
/* So far memory is freed only in the case of directoryName
|
||||
* parsing succeeding, as mbedtls_x509_dn_gets allocates memory. */
|
||||
mbedtls_x509_free_subject_alt_name(&san);
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user