diff options
author | Jiasheng Jiang <jiasheng@purdue.edu> | 2024-05-01 22:03:13 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2024-05-06 10:24:22 +0200 |
commit | 327261c076b8468382e1effea14d79446cc22b4d (patch) | |
tree | c549fe00018da403cab17673050b99e259b6cc78 /test/threadstest.c | |
parent | gitignore: ignore newly generated header (diff) | |
download | openssl-327261c076b8468382e1effea14d79446cc22b4d.tar.xz openssl-327261c076b8468382e1effea14d79446cc22b4d.zip |
test/threadstest.c: Add checks for CRYPTO_THREAD_lock_new()
Add checks for the return value of CRYPTO_THREAD_lock_new() in order to avoid Null pointer dereference.
Fixes: 5f8b812931 ("Add locking to atomic operations in rw/rcu tests")
Fixes: d0e1a0ae70 ("RCU lock implementation")
Fixes: 71a04cfca0 ("Implement new multi-threading API")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24313)
Diffstat (limited to 'test/threadstest.c')
-rw-r--r-- | test/threadstest.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/threadstest.c b/test/threadstest.c index 0e42d63e10..9a961bb5c4 100644 --- a/test/threadstest.c +++ b/test/threadstest.c @@ -90,6 +90,9 @@ static int test_lock(void) CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new(); int res; + if (!TEST_ptr(lock)) + return 0; + res = TEST_true(CRYPTO_THREAD_read_lock(lock)) && TEST_true(CRYPTO_THREAD_unlock(lock)) && TEST_true(CRYPTO_THREAD_write_lock(lock)) @@ -225,6 +228,9 @@ static int _torture_rw(void) rwtorturelock = CRYPTO_THREAD_lock_new(); atomiclock = CRYPTO_THREAD_lock_new(); + if (!TEST_ptr(rwtorturelock) || !TEST_ptr(atomiclock)) + goto out; + rwwriter1_iterations = 0; rwwriter2_iterations = 0; rwreader1_iterations = 0; @@ -413,6 +419,9 @@ static int _torture_rcu(void) int rc = 0; atomiclock = CRYPTO_THREAD_lock_new(); + if (!TEST_ptr(atomiclock)) + goto out; + memset(&writer1, 0, sizeof(thread_t)); memset(&writer2, 0, sizeof(thread_t)); memset(&reader1, 0, sizeof(thread_t)); @@ -427,6 +436,8 @@ static int _torture_rcu(void) rcu_torture_result = 1; rcu_lock = ossl_rcu_lock_new(1, NULL); + if (!rcu_lock) + goto out; TEST_info("Staring rcu torture"); t1 = ossl_time_now(); |