From a0c878481f30ba14e1ddadac3d836e5c3bff4218 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Fri, 2 Sep 2022 13:55:19 +0900 Subject: [PATCH] x509*: fix error queue leak in #extensions= and #attributes= methods X509at_delete_attr() in OpenSSL master puts an error queue entry if there is no attribute left to delete. We must either clear the error queue, or try not to call it when the list is already empty. --- ext/openssl/ossl_x509cert.c | 6 +++--- ext/openssl/ossl_x509crl.c | 6 +++--- ext/openssl/ossl_x509req.c | 6 +++--- ext/openssl/ossl_x509revoked.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c index 996f18417..944354164 100644 --- a/ext/openssl/ossl_x509cert.c +++ b/ext/openssl/ossl_x509cert.c @@ -642,12 +642,12 @@ ossl_x509_set_extensions(VALUE self, VALUE ary) OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext); } GetX509(self, x509); - while ((ext = X509_delete_ext(x509, 0))) - X509_EXTENSION_free(ext); + for (i = X509_get_ext_count(x509); i > 0; i--) + X509_EXTENSION_free(X509_delete_ext(x509, 0)); for (i=0; i 0; i--) + X509_EXTENSION_free(X509_CRL_delete_ext(crl, 0)); for (i=0; i 0; i--) + X509_ATTRIBUTE_free(X509_REQ_delete_attr(req, 0)); for (i=0;i 0; i--) + X509_EXTENSION_free(X509_REVOKED_delete_ext(rev, 0)); for (i=0; i