mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Merge pull request #1340 from mpg/fix-string-to-names-uaf-3.6
[3.6] Fix string to names memory management
This commit is contained in:
@ -292,8 +292,12 @@ int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *nam
|
||||
unsigned char data[MBEDTLS_X509_MAX_DN_NAME_SIZE];
|
||||
size_t data_len = 0;
|
||||
|
||||
/* Clear existing chain if present */
|
||||
mbedtls_asn1_free_named_data_list(head);
|
||||
/* Ensure the output parameter is not already populated.
|
||||
* (If it were, overwriting it would likely cause a memory leak.)
|
||||
*/
|
||||
if (*head != NULL) {
|
||||
return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
while (c <= end) {
|
||||
if (in_attr_type && *c == '=') {
|
||||
|
@ -84,12 +84,14 @@ void mbedtls_x509write_crt_set_issuer_key(mbedtls_x509write_cert *ctx,
|
||||
int mbedtls_x509write_crt_set_subject_name(mbedtls_x509write_cert *ctx,
|
||||
const char *subject_name)
|
||||
{
|
||||
mbedtls_asn1_free_named_data_list(&ctx->subject);
|
||||
return mbedtls_x509_string_to_names(&ctx->subject, subject_name);
|
||||
}
|
||||
|
||||
int mbedtls_x509write_crt_set_issuer_name(mbedtls_x509write_cert *ctx,
|
||||
const char *issuer_name)
|
||||
{
|
||||
mbedtls_asn1_free_named_data_list(&ctx->issuer);
|
||||
return mbedtls_x509_string_to_names(&ctx->issuer, issuer_name);
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ void mbedtls_x509write_csr_set_key(mbedtls_x509write_csr *ctx, mbedtls_pk_contex
|
||||
int mbedtls_x509write_csr_set_subject_name(mbedtls_x509write_csr *ctx,
|
||||
const char *subject_name)
|
||||
{
|
||||
mbedtls_asn1_free_named_data_list(&ctx->subject);
|
||||
return mbedtls_x509_string_to_names(&ctx->subject, subject_name);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user