1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Add missing deallocation of subject alt name

Since mbedtls_x509_get_name allocates memory
when parsing a directoryName, deallocation
has to be performed if anything fails in the
meantime.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
Andrzej Kurek
2023-02-27 16:03:41 -05:00
parent 532b8d41af
commit 5f0c6e82fb
2 changed files with 10 additions and 3 deletions

View File

@ -1590,10 +1590,15 @@ int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
case MBEDTLS_X509_SAN_DIRECTORY_NAME:
{
ret = mbedtls_snprintf(p, n, "\n%s directoryName : ", prefix);
if (ret < 0 || (size_t) ret >= n) {
mbedtls_x509_free_subject_alt_name(&san);
}
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_dn_gets(p, n, &san.san.directory_name);
if (ret < 0) {
mbedtls_x509_free_subject_alt_name(&san);
return ret;
}
@ -1611,7 +1616,7 @@ int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
}
/* So far memory is freed only in the case of directoryName
* parsing succeeding, as mbedtls_x509_dn_gets allocates memory. */
* parsing succeeding, as mbedtls_x509_get_name allocates memory. */
mbedtls_x509_free_subject_alt_name(&san);
cur = cur->next;
}