Patchwork [3/3] vnc: fix possible uninitialized removals

login
register
mail settings
Submitter Tim Hardeck
Date Dec. 7, 2012, 2:56 p.m.
Message ID <1354892195-18332-4-git-send-email-thardeck@suse.de>
Download mbox | patch
Permalink /patch/204521/
State New
Headers show

Comments

Tim Hardeck - Dec. 7, 2012, 2:56 p.m.
Some VncState values are not initialized before the Websocket handshake.
If it fails QEMU segfaults during the cleanup. To prevent this behavior
intialization checks are added.

Signed-off-by: Tim Hardeck <thardeck@suse.de>
---
 ui/vnc.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Patch

diff --git a/ui/vnc.c b/ui/vnc.c
index a5c16e0..3af1840 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1053,20 +1053,26 @@  void vnc_disconnect_finish(VncState *vs)
     audio_del(vs);
     vnc_release_modifiers(vs);
 
-    QTAILQ_REMOVE(&vs->vd->clients, vs, next);
+    if (!QTAILQ_EMPTY(&vs->vd->clients)) {
+        QTAILQ_REMOVE(&vs->vd->clients, vs, next);
+    }
 
     if (QTAILQ_EMPTY(&vs->vd->clients)) {
         dcl->idle = 1;
     }
 
-    qemu_remove_mouse_mode_change_notifier(&vs->mouse_mode_notifier);
+    if (vs->mouse_mode_notifier.notify != NULL) {
+        qemu_remove_mouse_mode_change_notifier(&vs->mouse_mode_notifier);
+    }
     vnc_remove_timer(vs->vd);
     if (vs->vd->lock_key_sync)
         qemu_remove_led_event_handler(vs->led);
     vnc_unlock_output(vs);
 
     qemu_mutex_destroy(&vs->output_mutex);
-    qemu_bh_delete(vs->bh);
+    if (vs->bh != NULL) {
+        qemu_bh_delete(vs->bh);
+    }
     buffer_free(&vs->jobs_buffer);
 
     for (i = 0; i < VNC_STAT_ROWS; ++i) {