[virt-tools-list] [virt-viewer v2] spice: avoid crashing when using invalid video config

Fabiano Fidêncio fidencio at redhat.com
Mon Apr 25 06:03:16 UTC 2016


virt-viewer _only_ supports guests that have either:

A) a signle graphics device with multiple displays (monitorid=0,
displayid=(0,1,2,3)).

B) multiple graphics device with a single display each
(monitorid=(0,1,2,3), displayid=0).

>From now on, avoid crashing connecting to a guest which has a graphics
configuration that violates A or B. However, even avoiding the crash, we
cannot ensure the guest will work as expected.

Resolves: rhbz#1250820

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 src/virt-viewer-display-spice.c | 7 +++++--
 src/virt-viewer-session-spice.c | 8 +++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index 4abab2c..7095930 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -286,8 +286,11 @@ virt_viewer_display_spice_new(VirtViewerSessionSpice *session,
     g_return_val_if_fail(SPICE_IS_DISPLAY_CHANNEL(channel), NULL);
 
     g_object_get(channel, "channel-id", &channelid, NULL);
-    // We don't allow monitorid != 0 && channelid != 0
-    g_return_val_if_fail(channelid == 0 || monitorid == 0, NULL);
+    if (channelid == 0 || monitorid == 0) {
+        g_warning("Unsupported graphics configuration:\n"
+                  "spice-gtk only supports multiple graphics channels if they are single-head");
+        return NULL;
+    }
 
     self = g_object_new(VIRT_VIEWER_TYPE_DISPLAY_SPICE,
                         "session", session,
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index f7f2dc9..6b6e32a 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -833,8 +833,11 @@ static void
 destroy_display(gpointer data)
 {
     VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(data);
-    VirtViewerSession *session = virt_viewer_display_get_session(display);
+    VirtViewerSession *session;
 
+    g_return_if_fail (display != NULL);
+
+    session = virt_viewer_display_get_session(display);
     g_debug("Destroying spice display %p", display);
     virt_viewer_session_remove_display(session, display);
     g_object_unref(display);
@@ -883,6 +886,9 @@ virt_viewer_session_spice_display_monitors(SpiceChannel *channel,
         display = g_ptr_array_index(displays, i);
         if (display == NULL) {
             display = virt_viewer_display_spice_new(self, channel, i);
+            if (display == NULL)
+                continue;
+
             g_debug("creating spice display (#:%d)",
                     virt_viewer_display_get_nth(VIRT_VIEWER_DISPLAY(display)));
             g_ptr_array_index(displays, i) = g_object_ref_sink(display);
-- 
2.7.3




More information about the virt-tools-list mailing list