summaryrefslogtreecommitdiffstats
path: root/test/threadstest.c
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2024-10-10 22:10:54 +0200
committerTomas Mraz <tomas@openssl.org>2024-12-10 14:57:53 +0100
commit420d5d6294449527f4dd986b4fed8681bd4ae8fb (patch)
tree4e7c131cb52c2649a1836dccebc8618d55668376 /test/threadstest.c
parentossl_cms_get1_crls_ex(): Avoid doublefree if CRL up ref fails (diff)
downloadopenssl-420d5d6294449527f4dd986b4fed8681bd4ae8fb.tar.xz
openssl-420d5d6294449527f4dd986b4fed8681bd4ae8fb.zip
Add test for releasing a shared EVP_PKEY across threads
Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/25664)
Diffstat (limited to '')
-rw-r--r--test/threadstest.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/threadstest.c b/test/threadstest.c
index faa9e2728c..3d7324cf6c 100644
--- a/test/threadstest.c
+++ b/test/threadstest.c
@@ -1014,6 +1014,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;
@@ -1306,6 +1345,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);
#if !defined(OPENSSL_NO_DGRAM) && !defined(OPENSSL_NO_SOCK)