really fix race conditions
authorBodo Möller <bodo@openssl.org>
Wed, 25 Sep 2002 15:36:21 +0000 (15:36 +0000)
committerBodo Möller <bodo@openssl.org>
Wed, 25 Sep 2002 15:36:21 +0000 (15:36 +0000)
Submitted by: "Patrick McCormick" <patrick@tellme.com>

PR: 262
PR: 291

CHANGES
ssl/s23_clnt.c
ssl/s23_srvr.c
ssl/s2_clnt.c
ssl/s2_lib.c
ssl/s2_srvr.c
ssl/s3_clnt.c
ssl/s3_lib.c
ssl/s3_srvr.c
ssl/t1_clnt.c
ssl/t1_srvr.c

diff --git a/CHANGES b/CHANGES
index cf9d6cdab9fc7960c07af00515d424d921956117..b40b9e87ae98f874fe78791307fa2e84b9ce4784 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -12,7 +12,9 @@
         SSLv23_client_method(),   SSLv23_server_method(),
         SSLv2_client_method(),    SSLv2_server_method(),
         SSLv3_client_method(),    SSLv3_server_method(),
-        TLSv1_client_method(),    TLSv1_server_method().
+        TLSv1_client_method(),    TLSv1_server_method(),
+        ssl2_get_cipher_by_char(),
+        ssl3_get_cipher_by_char().
      [Patrick McCormick <patrick@tellme.com>, Bodo Moeller]
 
   *) Reorder cleanup sequence in SSL_CTX_free(): only remove the ex_data after
index df9ed02ddd0a6dcc5997ec0302767741e3a99797..105e16aeae8404697c450c4b1e1541a2517b0a12 100644 (file)
@@ -89,11 +89,14 @@ SSL_METHOD *SSLv23_client_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&SSLv23_client_data,
-                       (char *)sslv23_base_method(),sizeof(SSL_METHOD));
-               SSLv23_client_data.ssl_connect=ssl23_connect;
-               SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
-               init=0;
+               if (init)
+                       {
+                       memcpy((char *)&SSLv23_client_data,
+                               (char *)sslv23_base_method(),sizeof(SSL_METHOD));
+                       SSLv23_client_data.ssl_connect=ssl23_connect;
+                       SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
+                       init=0;
+                       }
 
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
index 94198750f9edbad9cb1d2010f6006e8fdb2a2f96..40ffb65efd0a144d53034575cecd8c0043c67154 100644 (file)
@@ -141,11 +141,14 @@ SSL_METHOD *SSLv23_server_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&SSLv23_server_data,
-                       (char *)sslv23_base_method(),sizeof(SSL_METHOD));
-               SSLv23_server_data.ssl_accept=ssl23_accept;
-               SSLv23_server_data.get_ssl_method=ssl23_get_server_method;
-               init=0;
+               if (init)
+                       {
+                       memcpy((char *)&SSLv23_server_data,
+                               (char *)sslv23_base_method(),sizeof(SSL_METHOD));
+                       SSLv23_server_data.ssl_accept=ssl23_accept;
+                       SSLv23_server_data.get_ssl_method=ssl23_get_server_method;
+                       init=0;
+                       }
 
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
index c59fa6e4292419e8d653763217f7205831356a5e..3f56f6480b5bbb0390891349266629caed559cbb 100644 (file)
@@ -147,11 +147,14 @@ SSL_METHOD *SSLv2_client_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&SSLv2_client_data,(char *)sslv2_base_method(),
-                       sizeof(SSL_METHOD));
-               SSLv2_client_data.ssl_connect=ssl2_connect;
-               SSLv2_client_data.get_ssl_method=ssl2_get_client_method;
-               init=0;
+               if (init)
+                       {
+                       memcpy((char *)&SSLv2_client_data,(char *)sslv2_base_method(),
+                               sizeof(SSL_METHOD));
+                       SSLv2_client_data.ssl_connect=ssl2_connect;
+                       SSLv2_client_data.get_ssl_method=ssl2_get_client_method;
+                       init=0;
+                       }
 
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
index 01d1e97d60086f7b6a0316937756213dc6e0be46..0c96064675d14a7859aa8629952eaec14836adb1 100644 (file)
@@ -376,15 +376,19 @@ SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL);
 
-               for (i=0; i<SSL2_NUM_CIPHERS; i++)
-                       sorted[i]= &(ssl2_ciphers[i]);
+               if (init)
+                       {
+                       for (i=0; i<SSL2_NUM_CIPHERS; i++)
+                               sorted[i]= &(ssl2_ciphers[i]);
 
-               qsort(  (char *)sorted,
-                       SSL2_NUM_CIPHERS,sizeof(SSL_CIPHER *),
-                       FP_ICC ssl_cipher_ptr_id_cmp);
+                       qsort((char *)sorted,
+                               SSL2_NUM_CIPHERS,sizeof(SSL_CIPHER *),
+                               FP_ICC ssl_cipher_ptr_id_cmp);
 
+                       init=0;
+                       }
+                       
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
-               init=0;
                }
 
        id=0x02000000L|((unsigned long)p[0]<<16L)|
index 48fff175d4e80c8bccdcd01f46fb32ee2a0d718f..4ba8fb6534d57a859376948f9c44e856adfac7b5 100644 (file)
@@ -147,11 +147,14 @@ SSL_METHOD *SSLv2_server_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&SSLv2_server_data,(char *)sslv2_base_method(),
-                       sizeof(SSL_METHOD));
-               SSLv2_server_data.ssl_accept=ssl2_accept;
-               SSLv2_server_data.get_ssl_method=ssl2_get_server_method;
-               init=0;
+               if (init)
+                       {
+                       memcpy((char *)&SSLv2_server_data,(char *)sslv2_base_method(),
+                               sizeof(SSL_METHOD));
+                       SSLv2_server_data.ssl_accept=ssl2_accept;
+                       SSLv2_server_data.get_ssl_method=ssl2_get_server_method;
+                       init=0;
+                       }
 
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
index a55acd19752bb6dff6ebc9bee13dcb09e118a2d2..5927a2842c65b6c0831ba26b3d3b62542eee1c96 100644 (file)
@@ -148,11 +148,14 @@ SSL_METHOD *SSLv3_client_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(),
-                       sizeof(SSL_METHOD));
-               SSLv3_client_data.ssl_connect=ssl3_connect;
-               SSLv3_client_data.get_ssl_method=ssl3_get_client_method;
-               init=0;
+               if (init)
+                       {
+                       memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(),
+                               sizeof(SSL_METHOD));
+                       SSLv3_client_data.ssl_connect=ssl3_connect;
+                       SSLv3_client_data.get_ssl_method=ssl3_get_client_method;
+                       init=0;
+                       }
 
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
index 9951ebb4191ea62cb1d469597abdcba015cc9c86..c231d9d06fd89a008a2f3c364e459e97de03d3a2 100644 (file)
@@ -1084,16 +1084,19 @@ SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL);
 
-               for (i=0; i<SSL3_NUM_CIPHERS; i++)
-                       sorted[i]= &(ssl3_ciphers[i]);
+               if (init)
+                       {
+                       for (i=0; i<SSL3_NUM_CIPHERS; i++)
+                               sorted[i]= &(ssl3_ciphers[i]);
 
-               qsort(  (char *)sorted,
-                       SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
-                       FP_ICC ssl_cipher_ptr_id_cmp);
+                       qsort(sorted,
+                               SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
+                               FP_ICC ssl_cipher_ptr_id_cmp);
 
+                       init=0;
+                       }
+               
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
-
-               init=0;
                }
 
        id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
index 50913ae8e4aabef53a0dfe626914f778068bb23f..e4451e2bc77d912a790abd536cca5fe239293282 100644 (file)
@@ -153,12 +153,15 @@ SSL_METHOD *SSLv3_server_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
-                       sizeof(SSL_METHOD));
-               SSLv3_server_data.ssl_accept=ssl3_accept;
-               SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
-               init=0;
-
+               if (init)
+                       {
+                       memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
+                               sizeof(SSL_METHOD));
+                       SSLv3_server_data.ssl_accept=ssl3_accept;
+                       SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
+                       init=0;
+                       }
+                       
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
        return(&SSLv3_server_data);
index df00a1215af79d53a21952d72ea4d5af208e116b..f68b9cc085678ecf97f269440ba5a58820092775 100644 (file)
@@ -81,12 +81,15 @@ SSL_METHOD *TLSv1_client_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(),
-                       sizeof(SSL_METHOD));
-               TLSv1_client_data.ssl_connect=ssl3_connect;
-               TLSv1_client_data.get_ssl_method=tls1_get_client_method;
-               init=0;
-
+               if (init)
+                       {
+                       memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(),
+                               sizeof(SSL_METHOD));
+                       TLSv1_client_data.ssl_connect=ssl3_connect;
+                       TLSv1_client_data.get_ssl_method=tls1_get_client_method;
+                       init=0;
+                       }
+               
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
        return(&TLSv1_client_data);
index e62275c6f8145ead72e3f713a604ca7d21916beb..7486c553de4eb15f1c07d467d2f2d7f53359af78 100644 (file)
@@ -82,12 +82,15 @@ SSL_METHOD *TLSv1_server_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(),
-                       sizeof(SSL_METHOD));
-               TLSv1_server_data.ssl_accept=ssl3_accept;
-               TLSv1_server_data.get_ssl_method=tls1_get_server_method;
-               init=0;
-
+               if (init)
+                       {
+                       memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(),
+                               sizeof(SSL_METHOD));
+                       TLSv1_server_data.ssl_accept=ssl3_accept;
+                       TLSv1_server_data.get_ssl_method=tls1_get_server_method;
+                       init=0;
+                       }
+                       
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
        return(&TLSv1_server_data);