From: Bernd Edlinger Date: Sun, 31 Aug 2025 19:41:50 +0000 (+0200) Subject: Add a test for multi-threaded OBJ_create X-Git-Tag: openssl-3.6.0~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=174c992b15e9c91f4d888625eb1728019037b9a3;p=thirdparty%2Fopenssl.git Add a test for multi-threaded OBJ_create After a successful OBJ_create the returned NID should be the same NID that is returned from OBJ_ln2nid and should not change any more, but after an unsuccessful OBJ_create, another thread must have created the object, therefore OBJ_ln2nid should not return NID_undef in that case. Reviewed-by: Neil Horman Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/28582) (cherry picked from commit 5909d0d3fc9b99b7b9f0577d29515a72fa94bfa0) --- diff --git a/test/threadstest.c b/test/threadstest.c index c796300e6cc..e85bb8c8eec 100644 --- a/test/threadstest.c +++ b/test/threadstest.c @@ -1364,6 +1364,42 @@ static int test_x509_store(void) return ret; } +/* Test using OBJ_create in multiple threads */ +static void test_obj_create_worker(void) +{ + int i, nid, nid2; + time_t now; + char name[40]; + + for (i = 0; i < 4; i++) { + now = time(NULL); + sprintf(name, "Time in Seconds = %ld", (long) now); + while (now == time(NULL)) + /* no-op */; + nid = OBJ_create(NULL, NULL, name); + nid2 = OBJ_ln2nid(name); + if (nid != NID_undef) { + if (nid2 != nid) { + TEST_info("oops: name='%s' nid=%d nid2=%d", name, nid, nid2); + multi_set_success(0); + break; + } + } else { + if (nid2 == NID_undef) { + TEST_info("oops: name='%s' nid=%d nid2=%d", name, nid, nid2); + multi_set_success(0); + break; + } + } + } +} + +static int test_obj_stress(void) +{ + return thread_run_test(&test_obj_create_worker, MAXIMUM_THREADS, + &test_obj_create_worker, 0, NULL); +} + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, @@ -1453,6 +1489,7 @@ int setup_tests(void) #endif ADD_TEST(test_pem_read); ADD_TEST(test_x509_store); + ADD_TEST(test_obj_stress); return 1; }