Skip to contentSkip to conversation

fix segfaults triggered by failed vnc handshakes

PATCH New Tim Hardeck 1 participant 3 messages Oct 9, 2012

lore
Share & tools
lore
#2 lore raw

PATCH 2/2 qemu queue: fix uninitialized removals

In reply to Tim Hardeck

When calling QTAILQ_REMOVE or QLIST_REMOVE on an unitialized list QEMU segfaults.

Check for this case specifically on item removal.

---
 qemu-queue.h |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
qemu-queue.h +6 -2
index 9288cd8..47ed239 100644
@@ -141,7 +141,9 @@ struct {                                                                \
         if ((elm)->field.le_next != NULL)                               \
                 (elm)->field.le_next->field.le_prev =                   \
                     (elm)->field.le_prev;                               \
-        *(elm)->field.le_prev = (elm)->field.le_next;                   \
+        if ((elm)->field.le_prev != NULL) {                             \
+            *(elm)->field.le_prev = (elm)->field.le_next;               \
+        }                                                               \
 } while (/*CONSTCOND*/0)
 
 #define QLIST_FOREACH(var, head, field)                                 \
@@ -381,7 +383,9 @@ struct {                                                                \
                     (elm)->field.tqe_prev;                              \
         else                                                            \
                 (head)->tqh_last = (elm)->field.tqe_prev;               \
-        *(elm)->field.tqe_prev = (elm)->field.tqe_next;                 \
+        if ((elm)->field.tqe_prev != NULL) {                            \
+            *(elm)->field.tqe_prev = (elm)->field.tqe_next;             \
+        }                                                               \
 } while (/*CONSTCOND*/0)
 
 #define QTAILQ_FOREACH(var, head, field)                                \
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/2 vnc: fix segfault due to failed handshake

In reply to Tim Hardeck

When the VNC server disconnects due to a failed handshake we don't have vs->bh allocated yet.

Check for this case and don't delete it.

---
 ui/vnc.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ui/vnc.c +3 -1
index 01b2daf..656895a 100644
@@ -1055,7 +1055,9 @@ static void vnc_disconnect_finish(VncState *vs)
     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) {
Signature · 1 line
1.7.10.4
#0 lore raw

cover fix segfaults triggered by failed vnc handshakes

While trying to adapt Anthony Liguori's websockets patches to the current standard I ran into some segfaults.

They were triggered during disconnects due to failed VNC handshakes.

I have added checks to prevent them.

Tim Hardeck (2):
vnc: fix segfault due to failed handshake
qemu queue: fix uninitialized removals

 qemu-queue.h |    8 ++++++--
 ui/vnc.c     |    4 +++-
 2 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.10.4