From: Fabian Keil Date: Tue, 26 Nov 2019 12:05:12 +0000 (+0100) Subject: ssl_verify_callback(): Use malloc_or_die() X-Git-Tag: v_3_0_29~550 X-Git-Url: http://www.privoxy.org/gitweb/%40proxy-info-url%40?a=commitdiff_plain;h=906e31d202882a9e8712ea57edbf13163bab05b3;p=privoxy.git ssl_verify_callback(): Use malloc_or_die() --- diff --git a/ssl.c b/ssl.c index 220e099a..eb85ff2f 100644 --- a/ssl.c +++ b/ssl.c @@ -1829,38 +1829,28 @@ static int ssl_verify_callback(void *csp_void, mbedtls_x509_crt *crt, /* * Preparing next item in linked list for next certificate - * If malloc fails, we are continuing without this certificate */ - last->next = (struct certs_chain *)malloc(sizeof(struct certs_chain)); - if (last->next != NULL) - { - last->next->next = NULL; - memset(last->next->text_buf, 0, sizeof(last->next->text_buf)); - memset(last->next->file_buf, 0, sizeof(last->next->file_buf)); + last->next = malloc_or_die(sizeof(struct certs_chain)); + last->next->next = NULL; + memset(last->next->text_buf, 0, sizeof(last->next->text_buf)); + memset(last->next->file_buf, 0, sizeof(last->next->file_buf)); - /* - * Saving certificate file into buffer - */ - if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_CRT, PEM_END_CRT, - crt->raw.p, crt->raw.len, (unsigned char *)last->file_buf, - sizeof(last->file_buf)-1, &olen)) != 0) - { - return(ret); - } - - /* - * Saving certificate information into buffer - */ - mbedtls_x509_crt_info(last->text_buf, sizeof(last->text_buf) - 1, - CERT_INFO_PREFIX, crt); - } - else + /* + * Saving certificate file into buffer + */ + if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_CRT, PEM_END_CRT, + crt->raw.p, crt->raw.len, (unsigned char *)last->file_buf, + sizeof(last->file_buf)-1, &olen)) != 0) { - log_error(LOG_LEVEL_ERROR, - "Malloc memory for server certificate informations failed"); - return -1; + return(ret); } + /* + * Saving certificate information into buffer + */ + mbedtls_x509_crt_info(last->text_buf, sizeof(last->text_buf) - 1, + CERT_INFO_PREFIX, crt); + return 0; }