From: Jiasheng Jiang Date: Tue, 17 Jun 2025 20:11:50 +0000 (+0000) Subject: test/evp_extra_test.c: Add OPENSSL_free() to avoid memory leak if EVP_PKEY_CTX_set0_r... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d9b02304602d61e35570bd990faad89ee0ae7140;p=thirdparty%2Fopenssl.git test/evp_extra_test.c: Add OPENSSL_free() to avoid memory leak if EVP_PKEY_CTX_set0_rsa_oaep_label() fails 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 Reviewed-by: Paul Dale Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/27835) --- diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 5368c6266b8..3215ff655fe 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -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;