mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
Merge branch 'fix/esp_crt_bundle_allocator_symmetry' into 'master'
fix(esp_crt_bundle): match memory allocator in cross-signed callback Closes IDFGH-18243 See merge request espressif/esp-idf!52487
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
|
||||||
#include "mbedtls/pk.h"
|
#include "mbedtls/pk.h"
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
#include "mbedtls/oid.h"
|
#include "mbedtls/oid.h"
|
||||||
#include "mbedtls/asn1.h"
|
#include "mbedtls/asn1.h"
|
||||||
|
|
||||||
@@ -520,7 +521,7 @@ static int esp_crt_ca_cb_callback(void *ctx, mbedtls_x509_crt const *child, mbed
|
|||||||
}
|
}
|
||||||
// If we found a matching certificate, we need to allocate a new
|
// If we found a matching certificate, we need to allocate a new
|
||||||
// mbedtls_x509_crt structure and copy the certificate data into it.
|
// mbedtls_x509_crt structure and copy the certificate data into it.
|
||||||
mbedtls_x509_crt *new_cert = calloc(1, sizeof(mbedtls_x509_crt));
|
mbedtls_x509_crt *new_cert = mbedtls_calloc(1, sizeof(mbedtls_x509_crt));
|
||||||
if (unlikely(new_cert == NULL)) {
|
if (unlikely(new_cert == NULL)) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate memory for new certificate");
|
ESP_LOGE(TAG, "Failed to allocate memory for new certificate");
|
||||||
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
||||||
@@ -546,7 +547,7 @@ static int esp_crt_ca_cb_callback(void *ctx, mbedtls_x509_crt const *child, mbed
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ESP_LOGE(TAG, "Failed to parse public key from certificate: %d", ret);
|
ESP_LOGE(TAG, "Failed to parse public key from certificate: %d", ret);
|
||||||
mbedtls_x509_crt_free(new_cert);
|
mbedtls_x509_crt_free(new_cert);
|
||||||
free(new_cert);
|
mbedtls_free(new_cert);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,24 +557,24 @@ static int esp_crt_ca_cb_callback(void *ctx, mbedtls_x509_crt const *child, mbed
|
|||||||
if (esp_crt_ref_asn1(child_issuer, parent_subject) != 0) {
|
if (esp_crt_ref_asn1(child_issuer, parent_subject) != 0) {
|
||||||
ESP_LOGE(TAG, "Failed to reference ASN.1 data");
|
ESP_LOGE(TAG, "Failed to reference ASN.1 data");
|
||||||
mbedtls_x509_crt_free(new_cert);
|
mbedtls_x509_crt_free(new_cert);
|
||||||
free(new_cert);
|
mbedtls_free(new_cert);
|
||||||
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
child_issuer = child_issuer->next;
|
child_issuer = child_issuer->next;
|
||||||
while (child_issuer != NULL) {
|
while (child_issuer != NULL) {
|
||||||
parent_subject->next = calloc(1, sizeof(mbedtls_asn1_named_data));
|
parent_subject->next = mbedtls_calloc(1, sizeof(mbedtls_asn1_named_data));
|
||||||
if (parent_subject->next == NULL) {
|
if (parent_subject->next == NULL) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate memory for subject node");
|
ESP_LOGE(TAG, "Failed to allocate memory for subject node");
|
||||||
mbedtls_x509_crt_free(new_cert);
|
mbedtls_x509_crt_free(new_cert);
|
||||||
free(new_cert);
|
mbedtls_free(new_cert);
|
||||||
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
parent_subject = parent_subject->next;
|
parent_subject = parent_subject->next;
|
||||||
if (esp_crt_ref_asn1(child_issuer, parent_subject) != 0) {
|
if (esp_crt_ref_asn1(child_issuer, parent_subject) != 0) {
|
||||||
ESP_LOGE(TAG, "Failed to reference ASN.1 data");
|
ESP_LOGE(TAG, "Failed to reference ASN.1 data");
|
||||||
mbedtls_x509_crt_free(new_cert);
|
mbedtls_x509_crt_free(new_cert);
|
||||||
free(new_cert);
|
mbedtls_free(new_cert);
|
||||||
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
return MBEDTLS_ERR_X509_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
child_issuer = child_issuer->next;
|
child_issuer = child_issuer->next;
|
||||||
|
|||||||
Reference in New Issue
Block a user