From: Tomas Mraz Date: Mon, 3 Oct 2022 13:23:05 +0000 (+0200) Subject: CRYPTO_THREAD_lock_new(): Avoid infinite recursion on allocation error X-Git-Tag: openssl-3.2.0-alpha1~1969 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=894f2166ef2c16d8e4533e1c09e05ff31ea2f1d8;p=thirdparty%2Fopenssl.git CRYPTO_THREAD_lock_new(): Avoid infinite recursion on allocation error Fixes #19334 Reviewed-by: Richard Levitte Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/19335) --- diff --git a/crypto/threads_none.c b/crypto/threads_none.c index 2570efde237..b18587b9f21 100644 --- a/crypto/threads_none.c +++ b/crypto/threads_none.c @@ -21,10 +21,9 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void) { CRYPTO_RWLOCK *lock; - if ((lock = OPENSSL_zalloc(sizeof(unsigned int))) == NULL) { + if ((lock = CRYPTO_zalloc(sizeof(unsigned int), NULL, 0)) == NULL) /* Don't set error, to avoid recursion blowup. */ return NULL; - } *(unsigned int *)lock = 1; diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index bfc05a4e878..4aeba50479d 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -47,10 +47,9 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void) # ifdef USE_RWLOCK CRYPTO_RWLOCK *lock; - if ((lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t))) == NULL) { + if ((lock = CRYPTO_zalloc(sizeof(pthread_rwlock_t), NULL, 0)) == NULL) /* Don't set error, to avoid recursion blowup. */ return NULL; - } if (pthread_rwlock_init(lock, NULL) != 0) { OPENSSL_free(lock); @@ -60,10 +59,9 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void) pthread_mutexattr_t attr; CRYPTO_RWLOCK *lock; - if ((lock = OPENSSL_zalloc(sizeof(pthread_mutex_t))) == NULL) { + if ((lock = CRYPTO_zalloc(sizeof(pthread_mutex_t), NULL, 0)) == NULL) /* Don't set error, to avoid recursion blowup. */ return NULL; - } /* * We don't use recursive mutexes, but try to catch errors if we do. diff --git a/crypto/threads_win.c b/crypto/threads_win.c index b5e4d18a84d..3992ba4440b 100644 --- a/crypto/threads_win.c +++ b/crypto/threads_win.c @@ -43,16 +43,16 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void) # ifdef USE_RWLOCK CRYPTO_win_rwlock *rwlock; - if ((lock = OPENSSL_zalloc(sizeof(CRYPTO_win_rwlock))) == NULL) + if ((lock = CRYPTO_zalloc(sizeof(CRYPTO_win_rwlock), NULL, 0)) == NULL) + /* Don't set error, to avoid recursion blowup. */ return NULL; rwlock = lock; InitializeSRWLock(&rwlock->lock); # else - if ((lock = OPENSSL_zalloc(sizeof(CRITICAL_SECTION))) == NULL) { + if ((lock = CRYPTO_zalloc(sizeof(CRITICAL_SECTION), NULL, 0)) == NULL) /* Don't set error, to avoid recursion blowup. */ return NULL; - } # if !defined(_WIN32_WCE) /* 0x400 is the spin count value suggested in the documentation */