Blame SOURCES/kvm-vnc-add-magic-cookie-to-VncState.patch

4636b8
From c45e31fa19147b42c2e7c6a3ded711c24701f7a2 Mon Sep 17 00:00:00 2001
4636b8
From: jmaloy <jmaloy@redhat.com>
4636b8
Date: Thu, 28 May 2020 12:22:25 +0200
4636b8
Subject: [PATCH 1/2] vnc: add magic cookie to VncState
4636b8
4636b8
RH-Author: jmaloy <jmaloy@redhat.com>
4636b8
Message-id: <20200508213316.1251860-2-jmaloy@redhat.com>
4636b8
Patchwork-id: 96349
4636b8
O-Subject: [RHEL-7.9 qemu-kvm-rhev PATCH 1/2] vnc: add magic cookie to VncState
4636b8
Bugzilla: 1810409
4636b8
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
4636b8
RH-Acked-by: John Snow <jsnow@redhat.com>
4636b8
RH-Acked-by: Daniel P. Berrange <berrange@redhat.com>
4636b8
4636b8
From: Gerd Hoffmann <kraxel@redhat.com>
4636b8
4636b8
Set magic cookie on initialization.  Clear on cleanup.  Sprinkle a bunch
4636b8
of assert()s checking the cookie, to verify the pointer is valid.
4636b8
4636b8
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
4636b8
Message-id: 20180507102254.12107-1-kraxel@redhat.com
4636b8
4636b8
(cherry picked from commit f31f9c1080d8907c95f1501c6abab038eceb5490)
4636b8
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
4636b8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4636b8
---
4636b8
 ui/vnc-jobs.c |  4 ++++
4636b8
 ui/vnc.c      | 10 +++++++++-
4636b8
 ui/vnc.h      |  3 +++
4636b8
 3 files changed, 16 insertions(+), 1 deletion(-)
4636b8
4636b8
diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
4636b8
index 868ddde..b0b15d4 100644
4636b8
--- a/ui/vnc-jobs.c
4636b8
+++ b/ui/vnc-jobs.c
4636b8
@@ -82,6 +82,7 @@ VncJob *vnc_job_new(VncState *vs)
4636b8
 {
4636b8
     VncJob *job = g_new0(VncJob, 1);
4636b8
 
4636b8
+    assert(vs->magic == VNC_MAGIC);
4636b8
     job->vs = vs;
4636b8
     vnc_lock_queue(queue);
4636b8
     QLIST_INIT(&job->rectangles);
4636b8
@@ -214,6 +215,7 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
4636b8
     /* Here job can only be NULL if queue->exit is true */
4636b8
     job = QTAILQ_FIRST(&queue->jobs);
4636b8
     vnc_unlock_queue(queue);
4636b8
+    assert(job->vs->magic == VNC_MAGIC);
4636b8
 
4636b8
     if (queue->exit) {
4636b8
         return -1;
4636b8
@@ -236,6 +238,7 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
4636b8
 
4636b8
     /* Make a local copy of vs and switch output buffers */
4636b8
     vnc_async_encoding_start(job->vs, &vs);
4636b8
+    vs.magic = VNC_MAGIC;
4636b8
 
4636b8
     /* Start sending rectangles */
4636b8
     n_rectangles = 0;
4636b8
@@ -289,6 +292,7 @@ disconnected:
4636b8
     vnc_unlock_queue(queue);
4636b8
     qemu_cond_broadcast(&queue->cond);
4636b8
     g_free(job);
4636b8
+    vs.magic = 0;
4636b8
     return 0;
4636b8
 }
4636b8
 
4636b8
diff --git a/ui/vnc.c b/ui/vnc.c
4636b8
index 86c6762..fbd0da1 100644
4636b8
--- a/ui/vnc.c
4636b8
+++ b/ui/vnc.c
4636b8
@@ -1138,6 +1138,7 @@ static void audio_capture_notify(void *opaque, audcnotification_e cmd)
4636b8
 {
4636b8
     VncState *vs = opaque;
4636b8
 
4636b8
+    assert(vs->magic == VNC_MAGIC);
4636b8
     switch (cmd) {
4636b8
     case AUD_CNOTIFY_DISABLE:
4636b8
         vnc_lock_output(vs);
4636b8
@@ -1167,6 +1168,7 @@ static void audio_capture(void *opaque, void *buf, int size)
4636b8
 {
4636b8
     VncState *vs = opaque;
4636b8
 
4636b8
+    assert(vs->magic == VNC_MAGIC);
4636b8
     vnc_lock_output(vs);
4636b8
     if (vs->output.offset < vs->throttle_output_offset) {
4636b8
         vnc_write_u8(vs, VNC_MSG_SERVER_QEMU);
4636b8
@@ -1275,6 +1277,7 @@ void vnc_disconnect_finish(VncState *vs)
4636b8
     vs->ioc = NULL;
4636b8
     object_unref(OBJECT(vs->sioc));
4636b8
     vs->sioc = NULL;
4636b8
+    vs->magic = 0;
4636b8
     g_free(vs);
4636b8
 }
4636b8
 
4636b8
@@ -1414,7 +1417,7 @@ static void vnc_client_write_locked(VncState *vs)
4636b8
 
4636b8
 static void vnc_client_write(VncState *vs)
4636b8
 {
4636b8
-
4636b8
+    assert(vs->magic == VNC_MAGIC);
4636b8
     vnc_lock_output(vs);
4636b8
     if (vs->output.offset) {
4636b8
         vnc_client_write_locked(vs);
4636b8
@@ -1487,6 +1490,7 @@ static void vnc_jobs_bh(void *opaque)
4636b8
 {
4636b8
     VncState *vs = opaque;
4636b8
 
4636b8
+    assert(vs->magic == VNC_MAGIC);
4636b8
     vnc_jobs_consume_buffer(vs);
4636b8
 }
4636b8
 
4636b8
@@ -1537,6 +1541,8 @@ gboolean vnc_client_io(QIOChannel *ioc G_GNUC_UNUSED,
4636b8
                        GIOCondition condition, void *opaque)
4636b8
 {
4636b8
     VncState *vs = opaque;
4636b8
+
4636b8
+    assert(vs->magic == VNC_MAGIC);
4636b8
     if (condition & G_IO_IN) {
4636b8
         if (vnc_client_read(vs) < 0) {
4636b8
             goto end;
4636b8
@@ -1567,6 +1573,7 @@ end:
4636b8
 
4636b8
 void vnc_write(VncState *vs, const void *data, size_t len)
4636b8
 {
4636b8
+    assert(vs->magic == VNC_MAGIC);
4636b8
     if (vs->disconnecting) {
4636b8
         return;
4636b8
     }
4636b8
@@ -3063,6 +3070,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc,
4636b8
     int i;
4636b8
 
4636b8
     trace_vnc_client_connect(vs, sioc);
4636b8
+    vs->magic = VNC_MAGIC;
4636b8
     vs->sioc = sioc;
4636b8
     object_ref(OBJECT(vs->sioc));
4636b8
     vs->ioc = QIO_CHANNEL(sioc);
4636b8
diff --git a/ui/vnc.h b/ui/vnc.h
4636b8
index 7b29def..7626329 100644
4636b8
--- a/ui/vnc.h
4636b8
+++ b/ui/vnc.h
4636b8
@@ -255,8 +255,11 @@ typedef enum {
4636b8
     VNC_STATE_UPDATE_FORCE,
4636b8
 } VncStateUpdate;
4636b8
 
4636b8
+#define VNC_MAGIC ((uint64_t)0x05b3f069b3d204bb)
4636b8
+
4636b8
 struct VncState
4636b8
 {
4636b8
+    uint64_t magic;
4636b8
     QIOChannelSocket *sioc; /* The underlying socket */
4636b8
     QIOChannel *ioc; /* The channel currently used for I/O */
4636b8
     guint ioc_tag;
4636b8
-- 
4636b8
1.8.3.1
4636b8