From 8b089533e9c75bc6a99917cce71bc3839dd0ab44 Mon Sep 17 00:00:00 2001 From: fengweihao Date: Sat, 12 Oct 2019 18:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=97=E6=BC=8F=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E4=B8=BA=E4=B8=80=E5=B1=82=E5=85=AC=E9=92=A5?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cert_session.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cert_session.c b/src/cert_session.c index 425d843..8626e41 100644 --- a/src/cert_session.c +++ b/src/cert_session.c @@ -281,9 +281,9 @@ finish: X509* x509_get_root_ca(char *file, STACK_OF(X509) **stack_ca) { int x509_cnt = 0; - X509 *x = NULL, *end = NULL; BIO *bio = NULL; - STACK_OF(X509) *stack_x509 = NULL; + STACK_OF(X509) *stack_x509 = NULL; + X509 *x = NULL, *node = NULL, *root = NULL; if(!file){ mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Input cert file is empty."); @@ -307,12 +307,12 @@ X509* x509_get_root_ca(char *file, STACK_OF(X509) **stack_ca) while(NULL!=(x=PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL))){ if (0 == X509_NAME_cmp(X509_get_issuer_name(x), X509_get_subject_name(x))){ /*This is root ca**/ + root = x; continue; - X509_free(x); }; /*This is last ca*/ if (x509_get_last_ca(file, x) == 0){ - end = x; + node = x; continue; } sk_X509_push(stack_x509, x); @@ -320,10 +320,13 @@ X509* x509_get_root_ca(char *file, STACK_OF(X509) **stack_ca) } if (x509_cnt >= 1) *stack_ca = stack_x509; - + if (node != NULL) + X509_free(root); + else + node = root; BIO_free (bio); finish: - return end; + return node; } static X509 *