Blame SOURCES/0001-fix-crash-when-connection-fails-early.patch

a49c88
From ac1960bcc8e2678c0431d11eb7603ad674937f6d Mon Sep 17 00:00:00 2001
a49c88
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
a49c88
Date: Fri, 24 Aug 2018 17:18:04 +0100
a49c88
Subject: [PATCH] fix crash when connection fails early
a49c88
MIME-Version: 1.0
a49c88
Content-Type: text/plain; charset=UTF-8
a49c88
Content-Transfer-Encoding: 8bit
a49c88
a49c88
When reading the initial greeting a timer is set in the background. If
a49c88
the connection fails early, we can jump to cleanup code before the timer
a49c88
is disable. The timer will later fire, read a coroutine context from
a49c88
freed memory, and likely jump to somewhere awful with predictably crashy
a49c88
results.
a49c88
a49c88
  https://bugzilla.redhat.com/show_bug.cgi?id=1620203
a49c88
a49c88
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
a49c88
(cherry picked from commit 06a27a4fb52653b4cbf67b75b8116cf6692b435d)
a49c88
---
a49c88
 src/vncconnection.c | 15 ++++++++++++++-
a49c88
 1 file changed, 14 insertions(+), 1 deletion(-)
a49c88
a49c88
diff --git a/src/vncconnection.c b/src/vncconnection.c
a49c88
index b6e13d5..afc1418 100644
a49c88
--- a/src/vncconnection.c
a49c88
+++ b/src/vncconnection.c
a49c88
@@ -319,7 +319,9 @@ static gboolean vnc_connection_timeout(gpointer data)
a49c88
 {
a49c88
     struct wait_queue *wait = data;
a49c88
 
a49c88
+    VNC_DEBUG("Connection timeout wakeup start %p", data);
a49c88
     g_io_wakeup(wait);
a49c88
+    VNC_DEBUG("Connection timeout wakeup done %p", data);
a49c88
 
a49c88
     return FALSE;
a49c88
 }
a49c88
@@ -5318,6 +5320,7 @@ static gboolean vnc_connection_initialize(VncConnection *conn)
a49c88
 
a49c88
     priv->absPointer = TRUE;
a49c88
 
a49c88
+    VNC_DEBUG("Schedule greeting timeout %p", &priv->wait);
a49c88
     timeout = g_timeout_add_seconds(2, vnc_connection_timeout, &priv->wait);
a49c88
     want = 12;
a49c88
     while (want > 0) {
a49c88
@@ -5369,7 +5372,9 @@ static gboolean vnc_connection_initialize(VncConnection *conn)
a49c88
     }
a49c88
 
a49c88
     if (timeout != 0) {
a49c88
+        VNC_DEBUG("Remove timeout %p", &priv->wait);
a49c88
         g_source_remove(timeout);
a49c88
+        timeout = 0;
a49c88
     }
a49c88
 
a49c88
     version[12] = 0;
a49c88
@@ -5449,6 +5454,11 @@ static gboolean vnc_connection_initialize(VncConnection *conn)
a49c88
     return !vnc_connection_has_error(conn);
a49c88
 
a49c88
  fail:
a49c88
+    if (timeout != 0) {
a49c88
+        VNC_DEBUG("Remove timeout %p", &priv->wait);
a49c88
+        g_source_remove(timeout);
a49c88
+        timeout = 0;
a49c88
+    }
a49c88
     return !vnc_connection_has_error(conn);
a49c88
 }
a49c88
 
a49c88
@@ -5481,6 +5491,7 @@ static GSocket *vnc_connection_connect_socket(struct wait_queue *wait,
a49c88
     if (!sock)
a49c88
         return NULL;
a49c88
 
a49c88
+    VNC_DEBUG("Schedule socket timeout %p", wait);
a49c88
     guint timeout = g_timeout_add_seconds(10, vnc_connection_timeout, wait);
a49c88
 
a49c88
     g_socket_set_blocking(sock, FALSE);
a49c88
@@ -5513,8 +5524,10 @@ timeout:
a49c88
     sock = NULL;
a49c88
 
a49c88
 end:
a49c88
-    if (timeout != 0)
a49c88
+    if (timeout != 0) {
a49c88
+        VNC_DEBUG("Remove timeout %p", wait);
a49c88
         g_source_remove(timeout);
a49c88
+    }
a49c88
 
a49c88
     return sock;
a49c88
 }