[openssl-commits] [openssl] master update

bernd.edlinger at hotmail.de bernd.edlinger at hotmail.de
Tue May 1 15:34:28 UTC 2018


The branch master has been updated
       via  0e5c1a66f7911352a4db3bda2293b91858b9f33c (commit)
      from  5b748dea5dc6161d4a66d7804c580ec14e545ff7 (commit)


- Log -----------------------------------------------------------------
commit 0e5c1a66f7911352a4db3bda2293b91858b9f33c
Author: Bernd Edlinger <bernd.edlinger at hotmail.de>
Date:   Sat Apr 28 20:35:54 2018 +0200

    Improve error handling in rand_init function
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6124)

-----------------------------------------------------------------------

Summary of changes:
 crypto/rand/rand_lib.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
index 5ae51a1..8a657c5 100644
--- a/crypto/rand/rand_lib.c
+++ b/crypto/rand/rand_lib.c
@@ -310,19 +310,31 @@ void rand_fork()
 
 DEFINE_RUN_ONCE_STATIC(do_rand_init)
 {
-    int ret = 1;
-
 #ifndef OPENSSL_NO_ENGINE
     rand_engine_lock = CRYPTO_THREAD_lock_new();
-    ret &= rand_engine_lock != NULL;
+    if (rand_engine_lock == NULL)
+        return 0;
 #endif
+
     rand_meth_lock = CRYPTO_THREAD_lock_new();
-    ret &= rand_meth_lock != NULL;
+    if (rand_meth_lock == NULL)
+        goto err1;
 
     rand_nonce_lock = CRYPTO_THREAD_lock_new();
-    ret &= rand_meth_lock != NULL;
+    if (rand_nonce_lock == NULL)
+        goto err2;
 
-    return ret;
+    return 1;
+
+err2:
+    CRYPTO_THREAD_lock_free(rand_meth_lock);
+    rand_meth_lock = NULL;
+err1:
+#ifndef OPENSSL_NO_ENGINE
+    CRYPTO_THREAD_lock_free(rand_engine_lock);
+    rand_engine_lock = NULL;
+#endif
+    return 0;
 }
 
 void rand_cleanup_int(void)
@@ -334,9 +346,12 @@ void rand_cleanup_int(void)
     RAND_set_rand_method(NULL);
 #ifndef OPENSSL_NO_ENGINE
     CRYPTO_THREAD_lock_free(rand_engine_lock);
+    rand_engine_lock = NULL;
 #endif
     CRYPTO_THREAD_lock_free(rand_meth_lock);
+    rand_meth_lock = NULL;
     CRYPTO_THREAD_lock_free(rand_nonce_lock);
+    rand_nonce_lock = NULL;
 }
 
 /*


More information about the openssl-commits mailing list