]> granicus.if.org Git - openssl/commitdiff
Setting the ex_data index is unsafe in a threaded environment, so
authorRichard Levitte <levitte@openssl.org>
Mon, 6 Oct 2003 09:09:44 +0000 (09:09 +0000)
committerRichard Levitte <levitte@openssl.org>
Mon, 6 Oct 2003 09:09:44 +0000 (09:09 +0000)
let's wrap it with a lock.

crypto/comp/c_zlib.c
crypto/cryptlib.c
crypto/crypto.h

index c3167fcead0177f31825c14ac146ae3bde37355b..7553a2d107e52589e16b0db2935de5ead5520808 100644 (file)
@@ -178,9 +178,12 @@ static int zlib_stateful_init(COMP_CTX *ctx)
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
        if (zlib_stateful_ex_idx == -1)
                {
-               zlib_stateful_ex_idx =
-                       CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
-                               0,NULL,NULL,NULL,zlib_stateful_free_ex_data);
+               CRYPTO_w_lock(CRYPTO_LOCK_COMP);
+               if (zlib_stateful_ex_idx == -1)
+                       zlib_stateful_ex_idx =
+                               CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
+                                       0,NULL,NULL,NULL,zlib_stateful_free_ex_data);
+               CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
                if (zlib_stateful_ex_idx == -1)
                        goto err;
                }
index 9c38f15ab2b97c81f2da56b3a3f1755472074a08..009c3be4c0ac4a3546874399ec7b26782964e4a8 100644 (file)
@@ -168,7 +168,8 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
        "bn",
        "ec_pre_comp",
        "store",
-#if CRYPTO_NUM_LOCKS != 38
+       "comp",
+#if CRYPTO_NUM_LOCKS != 39
 # error "Inconsistency between crypto.h and cryptlib.c"
 #endif
        };
index dd90cfa55d0f312437abc149be71d8e25dd2149f..5238e530669a2dd104a02ee99e52b3bded783cd6 100644 (file)
@@ -203,7 +203,8 @@ typedef struct openssl_item_st
 #define CRYPTO_LOCK_BN                 35
 #define CRYPTO_LOCK_EC_PRE_COMP                36
 #define CRYPTO_LOCK_STORE              37
-#define CRYPTO_NUM_LOCKS               38
+#define CRYPTO_LOCK_COMP               38
+#define CRYPTO_NUM_LOCKS               39
 
 #define CRYPTO_LOCK            1
 #define CRYPTO_UNLOCK          2