]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add a test for multi-threaded OBJ_create
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Sun, 31 Aug 2025 19:41:50 +0000 (21:41 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 25 Sep 2025 09:24:21 +0000 (11:24 +0200)
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 <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28582)

(cherry picked from commit 5909d0d3fc9b99b7b9f0577d29515a72fa94bfa0)

test/threadstest.c

index c796300e6cc312cd4409b59b527e0eb2ab91747b..e85bb8c8eec72024d5d357ed8d9a59444919d9e9 100644 (file)
@@ -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;
 }