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

Alexandre Julliard julliard at winehq.org
Thu Oct 1 09:48:20 CDT 2009


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

Author: Juan Lang <juan.lang at gmail.com>
Date:   Wed Sep 30 09:02:49 2009 -0700

wininet: Protect OpenSSL initialization with critical section.

---

 dlls/wininet/netconnection.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/dlls/wininet/netconnection.c b/dlls/wininet/netconnection.c
index 2e97017..d54e3ac 100644
--- a/dlls/wininet/netconnection.c
+++ b/dlls/wininet/netconnection.c
@@ -98,6 +98,16 @@ WINE_DEFAULT_DEBUG_CHANNEL(wininet);
 
 #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 *OpenSSL_ssl_handle;
 static void *OpenSSL_crypto_handle;
 
@@ -142,14 +152,19 @@ BOOL NETCON_init(WININET_NETCONNECTION *connection, BOOL useSSL)
     {
 #if defined(SONAME_LIBSSL) && defined(SONAME_LIBCRYPTO)
         TRACE("using SSL connection\n");
+        EnterCriticalSection(&init_ssl_cs);
 	if (OpenSSL_ssl_handle) /* already initialized everything */
+        {
+            LeaveCriticalSection(&init_ssl_cs);
             return TRUE;
+        }
 	OpenSSL_ssl_handle = wine_dlopen(SONAME_LIBSSL, RTLD_NOW, NULL, 0);
 	if (!OpenSSL_ssl_handle)
 	{
 	    ERR("trying to use a SSL connection, but couldn't load %s. Expect trouble.\n",
 		SONAME_LIBSSL);
             INTERNET_SetLastError(ERROR_INTERNET_SECURITY_CHANNEL_ERROR);
+            LeaveCriticalSection(&init_ssl_cs);
             return FALSE;
 	}
 	OpenSSL_crypto_handle = wine_dlopen(SONAME_LIBCRYPTO, RTLD_NOW, NULL, 0);
@@ -158,6 +173,7 @@ BOOL NETCON_init(WININET_NETCONNECTION *connection, BOOL useSSL)
 	    ERR("trying to use a SSL connection, but couldn't load %s. Expect trouble.\n",
 		SONAME_LIBCRYPTO);
             INTERNET_SetLastError(ERROR_INTERNET_SECURITY_CHANNEL_ERROR);
+            LeaveCriticalSection(&init_ssl_cs);
             return FALSE;
 	}
 
@@ -168,6 +184,7 @@ BOOL NETCON_init(WININET_NETCONNECTION *connection, BOOL useSSL)
     { \
         ERR("failed to load symbol %s\n", #x); \
         INTERNET_SetLastError(ERROR_INTERNET_SECURITY_CHANNEL_ERROR); \
+        LeaveCriticalSection(&init_ssl_cs); \
         return FALSE; \
     }
 
@@ -196,6 +213,7 @@ BOOL NETCON_init(WININET_NETCONNECTION *connection, BOOL useSSL)
     { \
         ERR("failed to load symbol %s\n", #x); \
         INTERNET_SetLastError(ERROR_INTERNET_SECURITY_CHANNEL_ERROR); \
+        LeaveCriticalSection(&init_ssl_cs); \
         return FALSE; \
     }
 	DYNCRYPTO(BIO_new_fp);
@@ -215,8 +233,10 @@ BOOL NETCON_init(WININET_NETCONNECTION *connection, BOOL useSSL)
             ERR("SSL_CTX_set_default_verify_paths failed: %s\n",
                 pERR_error_string(pERR_get_error(), 0));
             INTERNET_SetLastError(ERROR_OUTOFMEMORY);
+            LeaveCriticalSection(&init_ssl_cs);
             return FALSE;
         }
+        LeaveCriticalSection(&init_ssl_cs);
 #else
 	FIXME("can't use SSL, not compiled in.\n");
         INTERNET_SetLastError(ERROR_INTERNET_SECURITY_CHANNEL_ERROR);




More information about the wine-cvs mailing list