]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
evp_extra_test2.c: Fix doublefree of PKEY and leak of RSA
authorTomas Mraz <tomas@openssl.org>
Mon, 23 Jun 2025 12:41:38 +0000 (14:41 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 23 Jun 2025 12:41:38 +0000 (14:41 +0200)
Fixes Coverity 1649567

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27880)

test/evp_extra_test2.c

index 90690bbeb52f2484d4d9d33f9d2201fa8ab89066..34cceb5ebfcb0cdae4414ab7e4c83bbdc3b7d709 100644 (file)
@@ -1271,14 +1271,15 @@ static int test_pkey_export(void)
     /* Now, try with a legacy key */
     pdata = keydata[0].kder;
     pdata_len = keydata[0].size;
-    if (!TEST_ptr(rsa = d2i_RSAPrivateKey(NULL, &pdata, pdata_len))
-        || !TEST_ptr(pkey = EVP_PKEY_new())
-        || !TEST_true(EVP_PKEY_assign_RSA(pkey, rsa))
+    if (!TEST_ptr(pkey = EVP_PKEY_new())
+        || !TEST_ptr(rsa = d2i_RSAPrivateKey(NULL, &pdata, pdata_len))
+        || !TEST_true(EVP_PKEY_set1_RSA(pkey, rsa))
         || !TEST_true(EVP_PKEY_export(pkey, EVP_PKEY_KEYPAIR,
                                       test_pkey_export_cb, pkey))
         || !TEST_false(EVP_PKEY_export(pkey, EVP_PKEY_KEYPAIR,
                                        test_pkey_export_cb, NULL)))
         ret = 0;
+    RSA_free(rsa);
     EVP_PKEY_free(pkey);
 #endif
     return ret;