really fix race conditions
authorBodo Möller <bodo@openssl.org>
Wed, 25 Sep 2002 15:38:17 +0000 (15:38 +0000)
committerBodo Möller <bodo@openssl.org>
Wed, 25 Sep 2002 15:38:17 +0000 (15:38 +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 001fd6e5c938fda3495d66629d7bee44df6406f2..09e6bc9e1915e424475ffe09bdeef24a1a29a74d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1683,7 +1683,9 @@ des-cbc           3624.96k     5258.21k     5530.91k     5624.30k     5628.26k
         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 9c02cb49a14fcdcbaea7dfba8b0cccf8ea2ccaf6..99230890a998666dda0aeb78516ae0b042538fde 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 5c7e9fa97fcd6a9d45819a1340393a6d34bfd58f..442c95aa9b545a08d6769269b7a73375865b8680 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 0d290398286a4e9c2e5090200c4a2cab278a4411..be03e9c63091d3effc293980df8688cbc4f6beda 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 cc0dcfa95685d1e1ed089b60639b18ab4b9e4e5e..0cbbb066fdd12c0bb44dd87867c57804a981f365 100644 (file)
@@ -377,15 +377,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 d64d4e1ede2b71a608e941e53fd31030e1707eb7..2efc14bc1a2d6b54f87dcb68ee75b39807dceece 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 59c79d3ae2cc819b4d4537946845ef97cb3bea03..ab974eba1dff0af683c122a1a674dd53a2df89b5 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 14b2f13ae2e9d271f740bbdb10e3a8647894d3b8..0f006fad005fdb042290dba59e283f6fc90160dd 100644 (file)
@@ -1341,16 +1341,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 22614f7c9a251140d2984e1c2bf1386e5da450d4..5b00d18a68ca6bb6094dbc4a35b1c685621d758d 100644 (file)
@@ -154,12 +154,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 3eb3ae56c51da445da32f8926c8ebe6e3d0c5ee6..57205fb429ab7bb2361c825e69838fbb5e7a860b 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 c72e5525ae1c6c997e63f1aea2fb5afb15e95de3..1c1149e49fe19b6a956200b96474009ca2418c38 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);