[openssl] master update

tmraz at fedoraproject.org tmraz at fedoraproject.org
Mon Mar 9 09:44:08 UTC 2020


The branch master has been updated
       via  86cd42fbd3752dec442780867434e828f9a1a749 (commit)
      from  8293fb6840840a5252bb6671c48486bc86857b5f (commit)


- Log -----------------------------------------------------------------
commit 86cd42fbd3752dec442780867434e828f9a1a749
Author: Davide Galassi <davxy at datawok.net>
Date:   Sun Feb 23 10:01:45 2020 +0100

    Remove double fetch of "OSSL_EX_DATA_GLOBAL" for global lock
    
    Fetch once and just pass the global ex_data to the "get_and_lock" static
    function.
    
    Removed a redundant null pointer check within the "get_and_lock" static
    function (control already performed by the caller).
    
    Reviewed-by: Matt Caswell <matt at openssl.org>
    Reviewed-by: Shane Lontis <shane.lontis at oracle.com>
    Reviewed-by: Tomas Mraz <tmraz at fedoraproject.org>
    (Merged from https://github.com/openssl/openssl/pull/11152)

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

Summary of changes:
 crypto/ex_data.c | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/crypto/ex_data.c b/crypto/ex_data.c
index 3cffef897b..defa2b4bda 100644
--- a/crypto/ex_data.c
+++ b/crypto/ex_data.c
@@ -24,19 +24,18 @@ int do_ex_data_init(OPENSSL_CTX *ctx)
 /*
  * Return the EX_CALLBACKS from the |ex_data| array that corresponds to
  * a given class.  On success, *holds the lock.*
+ * The |global| parameter is assumed to be non null (checked by the caller).
  */
-static EX_CALLBACKS *get_and_lock(OPENSSL_CTX *ctx, int class_index)
+static EX_CALLBACKS *get_and_lock(OSSL_EX_DATA_GLOBAL *global, int class_index)
 {
     EX_CALLBACKS *ip;
-    OSSL_EX_DATA_GLOBAL *global = NULL;
 
     if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {
         CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT);
         return NULL;
     }
 
-    global = openssl_ctx_get_ex_data_global(ctx);
-    if (global == NULL || global->ex_data_lock == NULL) {
+    if (global->ex_data_lock == NULL) {
         /*
          * If we get here, someone (who?) cleaned up the lock, so just
          * treat it as an error.
@@ -111,9 +110,10 @@ int crypto_free_ex_index_ex(OPENSSL_CTX *ctx, int class_index, int idx)
     if (global == NULL)
         return 0;
 
-    ip = get_and_lock(ctx, class_index);
+    ip = get_and_lock(global, class_index);
     if (ip == NULL)
         return 0;
+
     if (idx < 0 || idx >= sk_EX_CALLBACK_num(ip->meth))
         goto err;
     a = sk_EX_CALLBACK_value(ip->meth, idx);
@@ -149,7 +149,7 @@ int crypto_get_ex_new_index_ex(OPENSSL_CTX *ctx, int class_index, long argl,
     if (global == NULL)
         return -1;
 
-    ip = get_and_lock(ctx, class_index);
+    ip = get_and_lock(global, class_index);
     if (ip == NULL)
         return -1;
 
@@ -216,13 +216,12 @@ int crypto_new_ex_data_ex(OPENSSL_CTX *ctx, int class_index, void *obj,
     if (global == NULL)
         return 0;
 
-    ip = get_and_lock(ctx, class_index);
+    ip = get_and_lock(global, class_index);
     if (ip == NULL)
         return 0;
 
     ad->ctx = ctx;
     ad->sk = NULL;
-
     mx = sk_EX_CALLBACK_num(ip->meth);
     if (mx > 0) {
         if (mx < (int)OSSL_NELEM(stack))
@@ -269,16 +268,19 @@ int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
     EX_CALLBACK **storage = NULL;
     EX_CALLBACKS *ip;
     int toret = 0;
-    OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(from->ctx);
-
-    if (global == NULL)
-        return 0;
+    OSSL_EX_DATA_GLOBAL *global;
 
     to->ctx = from->ctx;
     if (from->sk == NULL)
         /* Nothing to copy over */
         return 1;
-    if ((ip = get_and_lock(from->ctx, class_index)) == NULL)
+
+    global = openssl_ctx_get_ex_data_global(from->ctx);
+    if (global == NULL)
+        return 0;
+
+    ip = get_and_lock(global, class_index);
+    if (ip == NULL)
         return 0;
 
     mx = sk_EX_CALLBACK_num(ip->meth);
@@ -340,14 +342,15 @@ void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
     EX_CALLBACK *f;
     EX_CALLBACK *stack[10];
     EX_CALLBACK **storage = NULL;
-    OSSL_EX_DATA_GLOBAL *global;
+    OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(ad->ctx);
 
-    if ((ip = get_and_lock(ad->ctx, class_index)) == NULL)
-        goto err;
-    global = openssl_ctx_get_ex_data_global(ad->ctx);
     if (global == NULL)
         goto err;
 
+    ip = get_and_lock(global, class_index);
+    if (ip == NULL)
+        goto err;
+
     mx = sk_EX_CALLBACK_num(ip->meth);
     if (mx > 0) {
         if (mx < (int)OSSL_NELEM(stack))
@@ -392,18 +395,18 @@ int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad,
     EX_CALLBACK *f;
     EX_CALLBACKS *ip;
     void *curval;
-    OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(ad->ctx);
-
-    if (global == NULL)
-        return 0;
+    OSSL_EX_DATA_GLOBAL *global;
 
     curval = CRYPTO_get_ex_data(ad, idx);
-
     /* Already there, no need to allocate */
     if (curval != NULL)
         return 1;
 
-    ip = get_and_lock(ad->ctx, class_index);
+    global = openssl_ctx_get_ex_data_global(ad->ctx);
+    if (global == NULL)
+        return 0;
+
+    ip = get_and_lock(global, class_index);
     if (ip == NULL)
         return 0;
     f = sk_EX_CALLBACK_value(ip->meth, idx);


More information about the openssl-commits mailing list