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



commit be9f7190b8c113586ae132359cc31663793c09d2
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 | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index b98cd2a..f948643 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,19 @@ accept_or_reject_peer_certificate (gpointer user_data)
 
   if (!accepted)
     {
-      g_main_context_pop_thread_default (priv->handshake_context);
+      g_mutex_lock (&priv->op_mutex);
+      if (priv->sync_handshake_in_progress)
+        g_main_context_pop_thread_default (priv->handshake_context);
+      g_mutex_unlock (&priv->op_mutex);
+
       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);
+
+      g_mutex_lock (&priv->op_mutex);
+      if (priv->sync_handshake_in_progress)
+        g_main_context_push_thread_default (priv->handshake_context);
+      g_mutex_unlock (&priv->op_mutex);
     }
 
   priv->peer_certificate_accepted = accepted;
@@ -2191,7 +2199,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 +2216,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]