From 371e0e45730bc40147ddda550db55855e90929fe Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Mon, 25 Feb 2019 18:08:59 +0000 Subject: [PATCH] Determine whether CRT is initialized or not through raw data pointer Previously, `mbedtls_x509_crt_der_internal()` used the `version` field (which is `0` after initialization but strictly greater than 0 once a CRT has successfully been parsed) to determine whether an `mbedtls_x509_crt` instance had already been setup. Preparating for the removal of `version` from the structure, this commit modifies the code to instead peek at the raw data pointer, which is NULL as long as the CRT structure hasn't been setup with a CRT, and will be kept in the new CRT structure. --- library/ssl_srv.c | 2 +- library/x509_crt.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/ssl_srv.c b/library/ssl_srv.c index 8ac7dd49b..9aef69a0f 100644 --- a/library/ssl_srv.c +++ b/library/ssl_srv.c @@ -2955,7 +2955,7 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl ) #endif crt = ssl->conf->ca_chain; - while( crt != NULL && crt->version != 0 ) + while( crt != NULL && crt->raw.p != NULL ) { dn_size = crt->subject_raw.len; diff --git a/library/x509_crt.c b/library/x509_crt.c index 63823d300..060c0158b 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1321,7 +1321,7 @@ static int mbedtls_x509_crt_parse_der_internal( mbedtls_x509_crt *chain, if( crt == NULL || buf == NULL ) return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); - while( crt->version != 0 && crt->next != NULL ) + while( crt->raw.p != NULL && crt->next != NULL ) { prev = crt; crt = crt->next; @@ -1330,7 +1330,7 @@ static int mbedtls_x509_crt_parse_der_internal( mbedtls_x509_crt *chain, /* * Add new certificate on the end of the chain if needed. */ - if( crt->version != 0 && crt->next == NULL ) + if( crt->raw.p != NULL && crt->next == NULL ) { crt->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );