]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/evp_extra_test.c: Add OPENSSL_free() to avoid memory leak if EVP_PKEY_CTX_set0_r...
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Tue, 17 Jun 2025 20:11:50 +0000 (20:11 +0000)
committerMatt Caswell <matt@openssl.org>
Wed, 18 Jun 2025 08:50:03 +0000 (09:50 +0100)
Add OPENSSL_free() to free 'label' if EVP_PKEY_CTX_set0_rsa_oaep_label() fails to avoid memory leak.

Fixes: 21b98da ("rsa: Accept NULL OAEP label for backward compatibility")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27835)

test/evp_extra_test.c

index 5368c6266b8b2ef651e72f11394c5c3ee5a01a64..3215ff655fe422f72a807cf739e707a0f36fd572 100644 (file)
@@ -3914,6 +3914,7 @@ static int test_RSA_OAEP_set_null_label(void)
     int ret = 0;
     EVP_PKEY *key = NULL;
     EVP_PKEY_CTX *key_ctx = NULL;
+    char *label = NULL;
 
     if (!TEST_ptr(key = load_example_rsa_key())
         || !TEST_ptr(key_ctx = EVP_PKEY_CTX_new_from_pkey(testctx, key, NULL))
@@ -3923,9 +3924,14 @@ static int test_RSA_OAEP_set_null_label(void)
     if (!TEST_true(EVP_PKEY_CTX_set_rsa_padding(key_ctx, RSA_PKCS1_OAEP_PADDING)))
         goto err;
 
-    if (!TEST_true(EVP_PKEY_CTX_set0_rsa_oaep_label(key_ctx, OPENSSL_strdup("foo"), 0)))
+    if (!TEST_ptr(label = OPENSSL_strdup("foo")))
         goto err;
 
+    if (!TEST_true(EVP_PKEY_CTX_set0_rsa_oaep_label(key_ctx, label, 0))) {
+        OPENSSL_free(label);
+        goto err;
+    }
+
     if (!TEST_true(EVP_PKEY_CTX_set0_rsa_oaep_label(key_ctx, NULL, 0)))
         goto err;