Juan Lang : winhttp: Protect OpenSSL initialization with critical section.

Alexandre Julliard julliard at winehq.org
Mon Oct 5 09:54:23 CDT 2009


Module: wine
Branch: master
Commit: 349e82508029bdd600704d5e34146d7251ee4f44
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=349e82508029bdd600704d5e34146d7251ee4f44

Author: Juan Lang <juan.lang at gmail.com>
Date:   Wed Sep 30 10:55:36 2009 -0700

winhttp: Protect OpenSSL initialization with critical section.

---

 dlls/winhttp/net.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/dlls/winhttp/net.c b/dlls/winhttp/net.c
index b264314..a824271 100644
--- a/dlls/winhttp/net.c
+++ b/dlls/winhttp/net.c
@@ -76,6 +76,16 @@ static CRITICAL_SECTION cs_gethostbyname = { &critsect_debug, -1, 0, 0, 0, 0 };
 
 #include <openssl/err.h>
 
+static CRITICAL_SECTION init_ssl_cs;
+static CRITICAL_SECTION_DEBUG init_ssl_cs_debug =
+{
+    0, 0, &init_ssl_cs,
+    { &init_ssl_cs_debug.ProcessLocksList,
+      &init_ssl_cs_debug.ProcessLocksList },
+    0, 0, { (DWORD_PTR)(__FILE__ ": init_ssl_cs") }
+};
+static CRITICAL_SECTION init_ssl_cs = { &init_ssl_cs_debug, -1, 0, 0, 0, 0 };
+
 static void *libssl_handle;
 static void *libcrypto_handle;
 
@@ -180,17 +190,24 @@ BOOL netconn_init( netconn_t *conn, BOOL secure )
     if (!secure) return TRUE;
 
 #if defined(SONAME_LIBSSL) && defined(SONAME_LIBCRYPTO)
-    if (libssl_handle) return TRUE;
+    EnterCriticalSection( &init_ssl_cs );
+    if (libssl_handle)
+    {
+        LeaveCriticalSection( &init_ssl_cs );
+        return TRUE;
+    }
     if (!(libssl_handle = wine_dlopen( SONAME_LIBSSL, RTLD_NOW, NULL, 0 )))
     {
         ERR("Trying to use SSL but couldn't load %s. Expect trouble.\n", SONAME_LIBSSL);
         set_last_error( ERROR_WINHTTP_SECURE_CHANNEL_ERROR );
+        LeaveCriticalSection( &init_ssl_cs );
         return FALSE;
     }
     if (!(libcrypto_handle = wine_dlopen( SONAME_LIBCRYPTO, RTLD_NOW, NULL, 0 )))
     {
         ERR("Trying to use SSL but couldn't load %s. Expect trouble.\n", SONAME_LIBCRYPTO);
         set_last_error( ERROR_WINHTTP_SECURE_CHANNEL_ERROR );
+        LeaveCriticalSection( &init_ssl_cs );
         return FALSE;
     }
 #define LOAD_FUNCPTR(x) \
@@ -198,6 +215,7 @@ BOOL netconn_init( netconn_t *conn, BOOL secure )
     { \
         ERR("Failed to load symbol %s\n", #x); \
         set_last_error( ERROR_WINHTTP_SECURE_CHANNEL_ERROR ); \
+        LeaveCriticalSection( &init_ssl_cs ); \
         return FALSE; \
     }
     LOAD_FUNCPTR( SSL_library_init );
@@ -221,6 +239,7 @@ BOOL netconn_init( netconn_t *conn, BOOL secure )
     { \
         ERR("Failed to load symbol %s\n", #x); \
         set_last_error( ERROR_WINHTTP_SECURE_CHANNEL_ERROR ); \
+        LeaveCriticalSection( &init_ssl_cs ); \
         return FALSE; \
     }
     LOAD_FUNCPTR( BIO_new_fp );
@@ -239,8 +258,10 @@ BOOL netconn_init( netconn_t *conn, BOOL secure )
     {
         ERR("SSL_CTX_set_default_verify_paths failed: %s\n", pERR_error_string( pERR_get_error(), 0 ));
         set_last_error( ERROR_OUTOFMEMORY );
+        LeaveCriticalSection( &init_ssl_cs );
         return FALSE;
     }
+    LeaveCriticalSection( &init_ssl_cs );
 #else
     WARN("SSL support not compiled in.\n");
     set_last_error( ERROR_WINHTTP_SECURE_CHANNEL_ERROR );




More information about the wine-cvs mailing list