Skip to content

Commit

Permalink
Fix a memory leak on successful load of CRL
Browse files Browse the repository at this point in the history
  • Loading branch information
beldmit committed Mar 7, 2024
1 parent cd10254 commit a2002fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crypto/x509/by_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion test/recipes/60-test_x509_load_cert_file.t
Original file line number Diff line number Diff line change
Expand Up @@ -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")])));
8 changes: 7 additions & 1 deletion test/x509_load_cert_file_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "testutil.h"

static const char *chain;
static const char *crl;

static int test_load_cert_file(void)
{
Expand All @@ -27,12 +28,15 @@ static int test_load_cert_file(void)
&& TEST_int_eq(sk_X509_num(certs), 4))
ret = 1;

if (crl != NULL && !TEST_true(X509_load_crl_file(lookup, crl, X509_FILETYPE_PEM)))
ret = 0;

OSSL_STACK_OF_X509_free(certs);
X509_STORE_free(store);
return ret;
}

OPT_TEST_DECLARE_USAGE("cert.pem...\n")
OPT_TEST_DECLARE_USAGE("cert.pem [crl.pem]\n")

int setup_tests(void)
{
Expand All @@ -45,6 +49,8 @@ int setup_tests(void)
if (chain == NULL)
return 0;

crl = test_get_argument(1);

ADD_TEST(test_load_cert_file);
return 1;
}

0 comments on commit a2002fd

Please sign in to comment.