[PATCH 2/2] Protect SSLRead/Write with critical section on OSX

Anton Romanov theli.ua at gmail.com
Wed Sep 13 00:33:54 CDT 2017


Signed-off-by: Anton Romanov <theli.ua at gmail.com>
---
 dlls/secur32/schannel_macosx.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/dlls/secur32/schannel_macosx.c b/dlls/secur32/schannel_macosx.c
index 4cd562411b..e02abf8369 100644
--- a/dlls/secur32/schannel_macosx.c
+++ b/dlls/secur32/schannel_macosx.c
@@ -184,6 +184,7 @@ enum {
 
 struct mac_session {
     SSLContextRef context;
+    CRITICAL_SECTION cs;
     struct schan_transport *push_transport;
     struct schan_transport *pull_transport;
 };
@@ -743,6 +744,9 @@ BOOL schan_imp_create_session(schan_imp_session *session, schan_credentials *cre
     if (!s)
         return FALSE;
 
+    InitializeCriticalSection(&s->cs);
+    DEBUG_SET_CRITSEC_NAME(&s->cs, "schannel_session");
+
     status = SSLNewContext(cred->credential_use == SECPKG_CRED_INBOUND, &s->context);
     if (status != noErr)
     {
@@ -804,6 +808,7 @@ void schan_imp_dispose_session(schan_imp_session session)
     status = SSLDisposeContext(s->context);
     if (status != noErr)
         ERR("Failed to dispose of session context: %d\n", status);
+    DeleteCriticalSection(&s->cs);
     HeapFree(GetProcessHeap(), 0, s);
 }
 
@@ -1093,7 +1098,9 @@ SECURITY_STATUS schan_imp_send(schan_imp_session session, const void *buffer,
 
     TRACE("(%p/%p, %p, %p/%lu)\n", s, s->context, buffer, length, *length);
 
+    EnterCriticalSection(&s->cs);
     status = SSLWrite(s->context, buffer, *length, length);
+    LeaveCriticalSection(&s->cs);
     if (status == noErr)
         TRACE("Wrote %lu bytes\n", *length);
     else if (status == errSSLWouldBlock)
@@ -1123,7 +1130,9 @@ SECURITY_STATUS schan_imp_recv(schan_imp_session session, void *buffer,
 
     TRACE("(%p/%p, %p, %p/%lu)\n", s, s->context, buffer, length, *length);
 
+    EnterCriticalSection(&s->cs);
     status = SSLRead(s->context, buffer, *length, length);
+    LeaveCriticalSection(&s->cs);
     if (status == noErr || status == errSSLClosedGraceful)
         TRACE("Read %lu bytes\n", *length);
     else if (status == errSSLWouldBlock)
-- 
2.11.0




More information about the wine-patches mailing list