Skip to contentSkip to conversation

spice-char: fix segfault in char_spice_finalize

PATCH Superseded Li Qiang 2 participants 2 messages Feb 21, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 spice-char: fix segfault in char_spice_finalize

In 'qemu_chr_open_spice_vmc' if the 'psubtype' is NULL, it will call 'char_spice_finalize'. But as the SpiceChardev is not inserted in the 'spice_chars' list, the 'QLIST_REMOVE' will cause a segfault. Add a detect to avoid it.

---
 spice-qemu-char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
spice-qemu-char.c +4 -1
index 6f46f46..15dbf9c 100644
@@ -215,7 +215,10 @@ static void char_spice_finalize(Object *obj)
     SpiceChardev *s = SPICE_CHARDEV(obj);
 
     vmc_unregister_interface(s);
-    QLIST_REMOVE(s, next);
+
+    if (spice_chars.lh_first) {
+        QLIST_REMOVE(s, next);
+    }
 
     g_free((char *)s->sin.subtype);
 #if SPICE_SERVER_VERSION >= 0x000c02
Signature · 1 line
1.8.3.1
#1 lore raw

Hi

Quoted 16 lines · Li Qiang

In 'qemu_chr_open_spice_vmc' if the 'psubtype' is NULL, it will call 'char_spice_finalize'. But as the SpiceChardev is not inserted in the 'spice_chars' list, the 'QLIST_REMOVE' will cause a segfault. Add a detect to avoid it.

---
 spice-qemu-char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
spice-qemu-char.c +0 -0
index 6f46f46..15dbf9c 100644

spice-qemu-char.c static void char_spice_finalize(Object *obj) · line 223

Quoted 10 lines
spice-qemu-char.c +4 -1
@@ -215,7 +215,10 @@ static void char_spice_finalize(Object *obj)
     SpiceChardev *s = SPICE_CHARDEV(obj);
 
     vmc_unregister_interface(s);
-    QLIST_REMOVE(s, next);
+
+    if (spice_chars.lh_first) {
+        QLIST_REMOVE(s, next);
+    }
 
 

The condition you added is unrelated. It should rather be "if (s->next.le_prev)". (there is a similar test in block.c)

     g_free((char *)s->sin.subtype);
Quoted 6 lines
spice-qemu-char.c +0 -1
 #if SPICE_SERVER_VERSION >= 0x000c02
--

1.8.3.1

--

Marc-André Lureau