summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshridhar kalavagunta <coolshrid@hotmail.com>2024-05-27 18:43:51 -0500
committerTomas Mraz <tomas@openssl.org>2024-05-30 18:44:32 +0200
commitc5f9b6d328f5916c86aa8c7114d8db38116761e2 (patch)
tree8151206f463759eaa899afbe6e174065f2eae937
parent7b50a23f8be965236aaa68483f7502b85ec1e340 (diff)
cmp_hdr_test.c: Fix leaks in error cases
Fixes #24475 Reviewed-by: Todd Short <todd.short@me.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/24511) (cherry picked from commit 0986e128ff258d482cab712aa617a533db5588ea)
-rw-r--r--test/cmp_hdr_test.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/test/cmp_hdr_test.c b/test/cmp_hdr_test.c
index ed49a0bb61..4308c0749b 100644
--- a/test/cmp_hdr_test.c
+++ b/test/cmp_hdr_test.c
@@ -71,25 +71,30 @@ static int test_HDR_set_get_pvno(void)
static int execute_HDR_get0_senderNonce_test(CMP_HDR_TEST_FIXTURE *fixture)
{
+ int res = 0;
X509_NAME *sender = X509_NAME_new();
ASN1_OCTET_STRING *sn;
if (!TEST_ptr(sender))
- return 0;
+ goto err;
X509_NAME_ADD(sender, "CN", "A common sender name");
if (!TEST_int_eq(OSSL_CMP_CTX_set1_subjectName(fixture->cmp_ctx, sender),
1))
- return 0;
+ goto err;
if (!TEST_int_eq(ossl_cmp_hdr_init(fixture->cmp_ctx, fixture->hdr),
1))
- return 0;
+ goto err;
sn = ossl_cmp_hdr_get0_senderNonce(fixture->hdr);
if (!TEST_int_eq(ASN1_OCTET_STRING_cmp(fixture->cmp_ctx->senderNonce, sn),
0))
- return 0;
+ goto err;
+
+ res = 1;
+err:
X509_NAME_free(sender);
- return 1;
+
+ return res;
}
static int test_HDR_get0_senderNonce(void)
@@ -102,23 +107,28 @@ static int test_HDR_get0_senderNonce(void)
static int execute_HDR_set1_sender_test(CMP_HDR_TEST_FIXTURE *fixture)
{
+ int res = 0;
X509_NAME *x509name = X509_NAME_new();
if (!TEST_ptr(x509name))
- return 0;
+ goto err;
X509_NAME_ADD(x509name, "CN", "A common sender name");
if (!TEST_int_eq(ossl_cmp_hdr_set1_sender(fixture->hdr, x509name), 1))
- return 0;
+ goto err;
+
if (!TEST_int_eq(fixture->hdr->sender->type, GEN_DIRNAME))
- return 0;
+ goto err;
if (!TEST_int_eq(X509_NAME_cmp(fixture->hdr->sender->d.directoryName,
x509name), 0))
- return 0;
+ goto err;
+ res = 1;
+err:
X509_NAME_free(x509name);
- return 1;
+
+ return res;
}
static int test_HDR_set1_sender(void)
@@ -131,24 +141,28 @@ static int test_HDR_set1_sender(void)
static int execute_HDR_set1_recipient_test(CMP_HDR_TEST_FIXTURE *fixture)
{
+ int res = 0;
X509_NAME *x509name = X509_NAME_new();
if (!TEST_ptr(x509name))
- return 0;
+ goto err;
X509_NAME_ADD(x509name, "CN", "A common recipient name");
if (!TEST_int_eq(ossl_cmp_hdr_set1_recipient(fixture->hdr, x509name), 1))
- return 0;
+ goto err;
if (!TEST_int_eq(fixture->hdr->recipient->type, GEN_DIRNAME))
- return 0;
+ goto err;
if (!TEST_int_eq(X509_NAME_cmp(fixture->hdr->recipient->d.directoryName,
x509name), 0))
- return 0;
+ goto err;
+ res = 1;
+err:
X509_NAME_free(x509name);
- return 1;
+
+ return res;
}
static int test_HDR_set1_recipient(void)
@@ -203,7 +217,7 @@ static int execute_HDR_set1_senderKID_test(CMP_HDR_TEST_FIXTURE *fixture)
int res = 0;
if (!TEST_ptr(senderKID))
- return 0;
+ goto err;
if (!TEST_int_eq(ASN1_OCTET_STRING_set(senderKID, rand_data,
sizeof(rand_data)), 1))
@@ -265,7 +279,7 @@ static int execute_HDR_push1_freeText_test(CMP_HDR_TEST_FIXTURE *fixture)
int res = 0;
if (!TEST_ptr(text))
- return 0;
+ goto err;
if (!ASN1_STRING_set(text, "A free text", -1))
goto err;
@@ -280,6 +294,7 @@ static int execute_HDR_push1_freeText_test(CMP_HDR_TEST_FIXTURE *fixture)
res = 1;
err:
ASN1_UTF8STRING_free(text);
+
return res;
}