[virt-tools-list] [PATCH virt-viewer 2/2] monitor-alignment: Do not crash on NULL display

Pavel Grunt pgrunt at redhat.com
Tue Jun 14 14:25:51 UTC 2016


Since commit 01b66ef88bc142d6716b40b1e384e94a2629a99f virt-viewer
does not crash on connection to a guest using an invalid display
configuration (eg. Cirrus & QXL vga). That commit allowed existence
of NULL display, however the code handling monitors alignment does
not expect this and crashes when virt-viewer is shifting/aligning
its windows.

Avoid crashing by returning early on NULL display.

 #0  0x0000000000411d0a in displays_cmp (p1=p1 at entry=0xbad940, p2=p2 at entry=0xbad944, user_data=user_data at entry=0x8eb180) at virt-viewer-util.c:544
 #1  0x00007ffff3f16ac5 in msort_with_tmp (p=0x7fffffffd670, b=0xbad940, n=2) at gqsort.c:93
 #2  0x00007ffff3f16ded in msort_r (b=b at entry=0xbad940, n=n at entry=2, s=s at entry=4, cmp=cmp at entry=0x411ce0 <displays_cmp>, arg=arg at entry=0x8eb180) at gqsort.c:278
 #3  0x00007ffff3f16e78 in g_qsort_with_data (pbase=pbase at entry=0xbad940, total_elems=total_elems at entry=2, size=size at entry=4, compare_func=compare_func at entry=0x411ce0 <displays_cmp>, user_data=user_data at entry=0x8eb180) at gqsort.c:303
 #4  0x000000000041277c in virt_viewer_align_monitors_linear (displays=displays at entry=0x8eb180 = {...}) at virt-viewer-util.c:586
 #5  0x000000000041a92d in virt_viewer_session_on_monitor_geometry_changed (self=0x8f38a0 [VirtViewerSessionSpice], display=<optimized out>) at virt-viewer-session.c:373
 #6  0x00007ffff4415908 in g_closure_invoke (closure=0x9306c0, return_value=return_value at entry=0x0, n_param_values=2, param_values=param_values at entry=0x7fffffffd960, invocation_hint=invocation_hint at entry=0x7fffffffd900)  at gclosure.c:801
 #7  0x00007ffff4427a1d in signal_emit_unlocked_R (node=node at entry=0x668f80, detail=detail at entry=1551, instance=instance at entry=0x930440, emission_return=emission_return at entry=0x0, instance_and_params=instance_and_params at entry=0x7fffffffd960) at gsignal.c:3627
 #8  0x00007ffff442fab1 in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args at entry=0x7fffffffdaf0) at gsignal.c:3383
 #9  0x00007ffff442fd9f in <emit signal notify:agent-connected on instance 0x930440 [SpiceMainChannel]> (instance=instance at entry=0x930440, signal_id=<optimized out>, detail=<optimized out>) at gsignal.c:3439
 #10 0x00007ffff4419fd4 in g_object_dispatch_properties_changed (object=0x930440 [SpiceMainChannel], n_pspecs=<optimized out>, pspecs=<optimized out> at gobject.c:1061
 #11 0x00007ffff441c4f9 in g_object_notify (pspec=<optimized out>, object=0x930440 [SpiceMainChannel]) at gobject.c:1155
 #12 0x00007ffff441c4f9 in g_object_notify (object=0x930440 [SpiceMainChannel], property_name=<optimized out>) at gobject.c:1202
 #13 0x00007ffff5a63dd0 in notify_main_context (opaque=0x7fffd6fde990) at gio-coroutine.c:240
 #14 0x00007ffff3f07d7a in g_main_context_dispatch (context=0x68da40) at gmain.c:3152
 #15 0x00007ffff3f07d7a in g_main_context_dispatch (context=context at entry=0x68da40) at gmain.c:3767
 #16 0x00007ffff3f080b8 in g_main_context_iterate (context=0x68da40, block=block at entry=1, dispatch=dispatch at entry=1, self=<optimized out>) at gmain.c:3838
 #17 0x00007ffff3f0838a in g_main_loop_run (loop=0x710de0) at gmain.c:4032
 #18 0x00007ffff5f53045 in gtk_main () at gtkmain.c:1207
 #19 0x0000000000411a22 in main (argc=1, argv=0x7fffffffdfa8)

Resolves: rhbz#1250820
---
 src/virt-viewer-util.c         |  3 +++
 tests/test-monitor-alignment.c | 43 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c
index ebe039c..7ad8066 100644
--- a/src/virt-viewer-util.c
+++ b/src/virt-viewer-util.c
@@ -528,6 +528,7 @@ displays_cmp(const void *p1, const void *p2, gpointer user_data)
     guint j = *(guint*)p2;
     GdkRectangle *m1 = g_hash_table_lookup(displays, GINT_TO_POINTER(i));
     GdkRectangle *m2 = g_hash_table_lookup(displays, GINT_TO_POINTER(j));
+    g_return_val_if_fail(m1 != NULL && m2 != NULL, 0);
     diff = m1->x - m2->x;
     if (diff == 0)
         diff = m1->y - m2->y;
@@ -578,6 +579,7 @@ virt_viewer_align_monitors_linear(GHashTable *displays)
         guint nth = sorted_displays[i];
         g_assert(nth < ndisplays);
         GdkRectangle *rect = g_hash_table_lookup(displays, GINT_TO_POINTER(nth));
+        g_return_if_fail(rect != NULL);
         rect->x = x;
         rect->y = 0;
         x += rect->width;
@@ -610,6 +612,7 @@ virt_viewer_shift_monitors_to_origin(GHashTable *displays)
     g_hash_table_iter_init(&iter, displays);
     while (g_hash_table_iter_next(&iter, NULL, &value)) {
         GdkRectangle *display = value;
+        g_return_if_fail(display != NULL);
         if (display->width > 0 && display->height > 0) {
             xmin = MIN(xmin, display->x);
             ymin = MIN(ymin, display->y);
diff --git a/tests/test-monitor-alignment.c b/tests/test-monitor-alignment.c
index 4d0bf9d..522483f 100644
--- a/tests/test-monitor-alignment.c
+++ b/tests/test-monitor-alignment.c
@@ -101,6 +101,24 @@ test_monitor_shift(void)
         {
             0, {NULL}, {NULL}, 0, {NULL}
         },{
+            1,
+            {NULL},
+            {NULL},
+            G_LOG_LEVEL_CRITICAL,
+            {"*assertion 'display != NULL' failed"}
+        },{
+            2,
+            {NULL, &rects[0]},
+            {NULL, &rects[0]},
+            G_LOG_LEVEL_CRITICAL,
+            {"*assertion 'display != NULL' failed"}
+        },{
+            2,
+            {&rects[2], NULL},
+            {&rects[2], NULL},
+            G_LOG_LEVEL_CRITICAL,
+            {"*assertion 'display != NULL' failed"}
+        },{
             2,
             {&rects[0], &rects[0]},
             {&rects[1], &rects[1]},
@@ -140,6 +158,31 @@ test_monitor_align_linear(void)
         {
             0, {NULL}, {NULL}, 0, {NULL}
         },{
+            1,
+            {NULL},
+            {NULL},
+            G_LOG_LEVEL_CRITICAL,
+            {"*assertion 'rect != NULL' failed"}
+        },{
+            2,
+            {NULL, &rects[1]},
+            {NULL, &rects[1]},
+            G_LOG_LEVEL_CRITICAL,
+            {
+                "*displays_cmp: assertion 'm1 != NULL && m2 != NULL' failed",
+                "*assertion 'rect != NULL' failed"
+            }
+        },{
+            3,
+            {&rects[1], NULL, &rects[0]},
+            {&rects[3], NULL, &rects[0]},
+            G_LOG_LEVEL_CRITICAL,
+            {
+                "*displays_cmp: assertion 'm1 != NULL && m2 != NULL' failed",
+                "*displays_cmp: assertion 'm1 != NULL && m2 != NULL' failed",
+                "*assertion 'rect != NULL' failed"
+            }
+        },{
             2,
             {&rects[0], &rects[1]},
             {&rects[0], &rects[2]},
-- 
2.8.4




More information about the virt-tools-list mailing list