Raise an Err when CRYPTO_THREAD_lock_new fails
authorFdaSilvaYY <fdasilvayy@gmail.com>
Sat, 30 Apr 2016 14:23:33 +0000 (16:23 +0200)
committerMatt Caswell <matt@openssl.org>
Wed, 1 Jun 2016 12:14:49 +0000 (13:14 +0100)
Add missing error raise call, as it is done everywhere else.
and as CRYPTO_THREAD_lock_new don't do it internally.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
crypto/asn1/tasn_utl.c
crypto/dh/dh_lib.c
crypto/dsa/dsa_lib.c
crypto/dso/dso_lib.c
engines/e_chil.c
engines/e_chil_err.h

index cb245939c46a1d09aea294859c1b5631b9daf888..f03f9e9ed04b5684daaa71463fc2b07b641569f6 100644 (file)
@@ -50,6 +50,7 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value,
  * then the count is incremented. If op is 0 count is set to 1. If op is -1
  * count is decremented and the return value is the current reference count
  * or 0 if no reference count exists.
  * then the count is incremented. If op is 0 count is set to 1. If op is -1
  * count is decremented and the return value is the current reference count
  * or 0 if no reference count exists.
+ * FIXME: return and manage any error from inside this method
  */
 
 int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
  */
 
 int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
@@ -68,8 +69,10 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
     if (op == 0) {
         *lck = 1;
         *lock = CRYPTO_THREAD_lock_new();
     if (op == 0) {
         *lck = 1;
         *lock = CRYPTO_THREAD_lock_new();
-        if (*lock == NULL)
+        if (*lock == NULL) {
+            /* FIXME: should report an error (-1) at this point */
             return 0;
             return 0;
+        }
         return 1;
     }
     CRYPTO_atomic_add(lck, op, &ret, *lock);
         return 1;
     }
     CRYPTO_atomic_add(lck, op, &ret, *lock);
index 8645b6728e779020e0b03a181afd97ae46c03d38..6a59f7faa4320a6ee055aa6f95bba371d073428a 100644 (file)
@@ -64,6 +64,7 @@ DH *DH_new_method(ENGINE *engine)
     ret->references = 1;
     ret->lock = CRYPTO_THREAD_lock_new();
     if (ret->lock == NULL) {
     ret->references = 1;
     ret->lock = CRYPTO_THREAD_lock_new();
     if (ret->lock == NULL) {
+        DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE);
         OPENSSL_free(ret);
         return NULL;
     }
         OPENSSL_free(ret);
         return NULL;
     }
index 92945943e4dc7ffe3025d03901d2681afe8725fc..14cb35f82e28f374afa67adff817d61d228a6fb1 100644 (file)
@@ -73,6 +73,7 @@ DSA *DSA_new_method(ENGINE *engine)
     ret->references = 1;
     ret->lock = CRYPTO_THREAD_lock_new();
     if (ret->lock == NULL) {
     ret->references = 1;
     ret->lock = CRYPTO_THREAD_lock_new();
     if (ret->lock == NULL) {
+        DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE);
         OPENSSL_free(ret);
         return NULL;
     }
         OPENSSL_free(ret);
         return NULL;
     }
index 6bb9f5f18431a9f4ed98d229d40fa86294c9bed9..bea8776d71b83bc2afd8b559ea1a464ddf9c2fbb 100644 (file)
@@ -39,6 +39,7 @@ static DSO *DSO_new_method(DSO_METHOD *meth)
     ret->references = 1;
     ret->lock = CRYPTO_THREAD_lock_new();
     if (ret->lock == NULL) {
     ret->references = 1;
     ret->lock = CRYPTO_THREAD_lock_new();
     if (ret->lock == NULL) {
+        DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE);
         sk_void_free(ret->meth_data);
         OPENSSL_free(ret);
         return NULL;
         sk_void_free(ret->meth_data);
         OPENSSL_free(ret);
         return NULL;
index 0fb7aa49e837d2527032df2a30dcc07c33302a01..c660aa97b7ffc2d3cfb654cdefb76e6f510b92c0 100644 (file)
@@ -309,8 +309,10 @@ static int bind_helper(ENGINE *e)
 #  endif
 
     chil_lock = CRYPTO_THREAD_lock_new();
 #  endif
 
     chil_lock = CRYPTO_THREAD_lock_new();
-    if (chil_lock == NULL)
+    if (chil_lock == NULL) {
+        HWCRHKerr(HWCRHK_F_BIND_HELPER, ERR_R_MALLOC_FAILURE);
         return 0;
         return 0;
+    }
 
     if (!ENGINE_set_id(e, engine_hwcrhk_id) ||
         !ENGINE_set_name(e, engine_hwcrhk_name) ||
 
     if (!ENGINE_set_id(e, engine_hwcrhk_id) ||
         !ENGINE_set_name(e, engine_hwcrhk_name) ||
@@ -1092,8 +1094,10 @@ static int hwcrhk_mutex_init(HWCryptoHook_Mutex * mt,
                              HWCryptoHook_CallerContext * cactx)
 {
     mt->lock = CRYPTO_THREAD_lock_new();
                              HWCryptoHook_CallerContext * cactx)
 {
     mt->lock = CRYPTO_THREAD_lock_new();
-    if (mt->lock == NULL)
+    if (mt->lock == NULL) {
+        HWCRHKerr(HWCRHK_F_HWCRHK_MUTEX_INIT, ERR_R_MALLOC_FAILURE);
         return 1;               /* failure */
         return 1;               /* failure */
+    }
     return 0;                   /* success */
 }
 
     return 0;                   /* success */
 }
 
index 42fdd19f2844613de3cff187617b5a766720c372..b0f0dd98d3d54e3101a24912885f4f6a6c06c5e1 100644 (file)
@@ -39,6 +39,8 @@ static void ERR_HWCRHK_error(int function, int reason, char *file, int line);
 # define HWCRHK_F_HWCRHK_MOD_EXP                          107
 # define HWCRHK_F_HWCRHK_RAND_BYTES                       108
 # define HWCRHK_F_HWCRHK_RSA_MOD_EXP                      109
 # define HWCRHK_F_HWCRHK_MOD_EXP                          107
 # define HWCRHK_F_HWCRHK_RAND_BYTES                       108
 # define HWCRHK_F_HWCRHK_RSA_MOD_EXP                      109
+# define HWCRHK_F_BIND_HELPER                             110
+# define HWCRHK_F_HWCRHK_MUTEX_INIT                       111
 
 /* Reason codes. */
 # define HWCRHK_R_ALREADY_LOADED                          100
 
 /* Reason codes. */
 # define HWCRHK_R_ALREADY_LOADED                          100