From: Tim Rühsen Date: Mon, 7 Aug 2017 21:04:36 +0000 (+0200) Subject: Fix memleaks in gnutls_x509_trust_list_add_crls() X-Git-Tag: gnutls_3_6_0~87 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=950fced8febacb419d15bc2f84d02eefcb4f2046;p=thirdparty%2Fgnutls.git Fix memleaks in gnutls_x509_trust_list_add_crls() Signed-off-by: Tim Rühsen --- diff --git a/lib/x509/verify-high.c b/lib/x509/verify-high.c index d78a2d4b7b..69fc0f2e68 100644 --- a/lib/x509/verify-high.c +++ b/lib/x509/verify-high.c @@ -708,6 +708,7 @@ gnutls_x509_trust_list_add_crls(gnutls_x509_trust_list_t list, unsigned x, i, j = 0; unsigned int vret = 0; uint32_t hash; + gnutls_x509_crl_t *tmp; /* Probably we can optimize things such as removing duplicates * etc. @@ -733,6 +734,8 @@ gnutls_x509_trust_list_add_crls(gnutls_x509_trust_list_t list, &vret); if (ret < 0 || vret != 0) { _gnutls_debug_log("CRL verification failed, not adding it\n"); + if (flags & GNUTLS_TL_NO_DUPLICATES) + gnutls_x509_crl_deinit(crl_list[i]); continue; } } @@ -752,22 +755,28 @@ gnutls_x509_trust_list_add_crls(gnutls_x509_trust_list_t list, } else { /* The new is older, discard it */ gnutls_x509_crl_deinit(crl_list[i]); - continue; + goto next; } } } } - list->node[hash].crls = - gnutls_realloc_fast(list->node[hash].crls, + tmp = + gnutls_realloc(list->node[hash].crls, (list->node[hash].crl_size + 1) * sizeof(list->node[hash]. trusted_cas[0])); - if (list->node[hash].crls == NULL) { + if (tmp == NULL) { + ret = i; gnutls_assert(); - return i; + if (flags & GNUTLS_TL_NO_DUPLICATES) + while (i < crl_size) + gnutls_x509_crl_deinit(crl_list[i++]); + return ret; } + list->node[hash].crls = tmp; + list->node[hash].crls[list->node[hash].crl_size] = crl_list[i];