[glib-networking/mcatanzaro/#85-glib-2-60] gnutls: fix invalid push/pop of handshake_context



commit 174e3ece4065645171bbfb215e46f232d17a0cec
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Fri May 17 16:58:14 2019 -0500

    gnutls: fix invalid push/pop of handshake_context
    
    This will address #85 for the 2.60 branch.

 tls/gnutls/gtlsconnection-gnutls.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index b98cd2a..869c68b 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -203,7 +203,7 @@ typedef struct
    * future operations). ever_handshaked indicates that TLS has
    * been successfully negotiated at some point.
    */
-  gboolean need_handshake, need_finish_handshake, sync_handshake_completed;
+  gboolean need_handshake, need_finish_handshake, sync_handshake_in_progress;
   gboolean started_handshake, handshaking, ever_handshaked;
   GMainContext *handshake_context;
   GTask *implicit_handshake;
@@ -1896,11 +1896,21 @@ accept_or_reject_peer_certificate (gpointer user_data)
 
   if (!accepted)
     {
-      g_main_context_pop_thread_default (priv->handshake_context);
+      gboolean sync_handshake_in_progress;
+
+      g_mutex_lock (&priv->op_mutex);
+      sync_handshake_in_progress = priv->sync_handshake_in_progress;
+      g_mutex_unlock (&priv->op_mutex);
+
+      if (sync_handshake_in_progress)
+        g_main_context_pop_thread_default (priv->handshake_context);
+
       accepted = g_tls_connection_emit_accept_certificate (G_TLS_CONNECTION (gnutls),
                                                            priv->peer_certificate,
                                                            priv->peer_certificate_errors);
-      g_main_context_push_thread_default (priv->handshake_context);
+
+      if (sync_handshake_in_progress)
+        g_main_context_push_thread_default (priv->handshake_context);
     }
 
   priv->peer_certificate_accepted = accepted;
@@ -2191,7 +2201,7 @@ sync_handshake_thread_completed (GObject      *object,
   g_assert (g_main_context_is_owner (priv->handshake_context));
 
   g_mutex_lock (&priv->op_mutex);
-  priv->sync_handshake_completed = TRUE;
+  priv->sync_handshake_in_progress = FALSE;
   g_mutex_unlock (&priv->op_mutex);
 
   g_main_context_wakeup (priv->handshake_context);
@@ -2208,8 +2218,8 @@ crank_sync_handshake_context (GTlsConnectionGnutls *gnutls,
    * here. So need_finish_handshake should only change on this thread.
    */
   g_mutex_lock (&priv->op_mutex);
-  priv->sync_handshake_completed = FALSE;
-  while (!priv->sync_handshake_completed && !g_cancellable_is_cancelled (cancellable))
+  priv->sync_handshake_in_progress = TRUE;
+  while (priv->sync_handshake_in_progress && !g_cancellable_is_cancelled (cancellable))
     {
       g_mutex_unlock (&priv->op_mutex);
       g_main_context_iteration (priv->handshake_context, TRUE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]