From: Dmitry Belyavskiy Date: Tue, 27 Feb 2024 14:22:58 +0000 (+0100) Subject: Fix a memory leak on successful load of CRL X-Git-Tag: openssl-3.3.0-alpha1~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6134e8e6ddc25c403fd1fab3f510a850a8843e62;p=thirdparty%2Fopenssl.git Fix a memory leak on successful load of CRL Fixes #23693 Reviewed-by: David von Oheimb Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/23695) --- diff --git a/crypto/x509/by_file.c b/crypto/x509/by_file.c index 5073c137a20..85923804ac7 100644 --- a/crypto/x509/by_file.c +++ b/crypto/x509/by_file.c @@ -198,6 +198,8 @@ int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) goto err; } count++; + X509_CRL_free(x); + x = NULL; } } else if (type == X509_FILETYPE_ASN1) { x = d2i_X509_CRL_bio(in, NULL); diff --git a/test/recipes/60-test_x509_load_cert_file.t b/test/recipes/60-test_x509_load_cert_file.t index 75aeac362c2..e329d7675c4 100644 --- a/test/recipes/60-test_x509_load_cert_file.t +++ b/test/recipes/60-test_x509_load_cert_file.t @@ -12,4 +12,5 @@ setup("test_load_cert_file"); plan tests => 1; -ok(run(test(["x509_load_cert_file_test", srctop_file("test", "certs", "leaf-chain.pem")]))); +ok(run(test(["x509_load_cert_file_test", srctop_file("test", "certs", "leaf-chain.pem"), + srctop_file("test", "certs", "cyrillic_crl.pem")]))); diff --git a/test/x509_load_cert_file_test.c b/test/x509_load_cert_file_test.c index 001ed570d3c..16caf48fec7 100644 --- a/test/x509_load_cert_file_test.c +++ b/test/x509_load_cert_file_test.c @@ -12,6 +12,7 @@ #include "testutil.h" static const char *chain; +static const char *crl; static int test_load_cert_file(void) { @@ -36,6 +37,9 @@ static int test_load_cert_file(void) goto err; } + if (crl != NULL && !TEST_true(X509_load_crl_file(lookup, crl, X509_FILETYPE_PEM))) + goto err; + ret = 1; err: @@ -45,7 +49,7 @@ err: return ret; } -OPT_TEST_DECLARE_USAGE("cert.pem...\n") +OPT_TEST_DECLARE_USAGE("cert.pem [crl.pem]\n") int setup_tests(void) { @@ -58,6 +62,8 @@ int setup_tests(void) if (chain == NULL) return 0; + crl = test_get_argument(1); + ADD_TEST(test_load_cert_file); return 1; }