spice: avoid crashing when using invalid video config

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@redhat.com>
This commit is contained in:
Fabiano Fidêncio 2016-03-15 16:51:41 +01:00
parent 4048d28de8
commit 01b66ef88b
2 changed files with 12 additions and 3 deletions

View File

@ -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,

View File

@ -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);