]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add test for releasing a shared EVP_PKEY across threads
authorTomas Mraz <tomas@openssl.org>
Thu, 10 Oct 2024 20:10:54 +0000 (22:10 +0200)
committerTomas Mraz <tomas@openssl.org>
Tue, 10 Dec 2024 13:58:59 +0000 (14:58 +0100)
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25664)

(cherry picked from commit 420d5d6294449527f4dd986b4fed8681bd4ae8fb)

test/threadstest.c

index 489acb99e3126a12847e245badef9c4975eab9eb..9302fed1d68aeb7dddc0070edca0a2d3a709885d 100644 (file)
@@ -968,6 +968,45 @@ static int test_multi_shared_pkey(void)
     return test_multi_shared_pkey_common(&thread_shared_evp_pkey);
 }
 
+static void thread_release_shared_pkey(void)
+{
+    OSSL_sleep(0);
+    EVP_PKEY_free(shared_evp_pkey);
+}
+
+static int test_multi_shared_pkey_release(void)
+{
+    int testresult = 0;
+    size_t i = 1;
+
+    multi_intialise();
+    shared_evp_pkey = NULL;
+    if (!thread_setup_libctx(1, do_fips ? fips_and_default_providers
+                                        : default_provider)
+            || !TEST_ptr(shared_evp_pkey = load_pkey_pem(privkey, multi_libctx)))
+        goto err;
+    for (; i < 10; ++i) {
+        if (!TEST_true(EVP_PKEY_up_ref(shared_evp_pkey)))
+            goto err;
+    }
+
+    if (!start_threads(10, &thread_release_shared_pkey))
+        goto err;
+    i = 0;
+
+    if (!teardown_threads()
+            || !TEST_true(multi_success))
+        goto err;
+    testresult = 1;
+ err:
+    while (i > 0) {
+        EVP_PKEY_free(shared_evp_pkey);
+        --i;
+    }
+    thead_teardown_libctx();
+    return testresult;
+}
+
 static int test_multi_load_unload_provider(void)
 {
     EVP_MD *sha256 = NULL;
@@ -1273,6 +1312,7 @@ int setup_tests(void)
 #ifndef OPENSSL_NO_DEPRECATED_3_0
     ADD_TEST(test_multi_downgrade_shared_pkey);
 #endif
+    ADD_TEST(test_multi_shared_pkey_release);
     ADD_TEST(test_multi_load_unload_provider);
     ADD_TEST(test_obj_add);
     ADD_TEST(test_lib_ctx_load_config);