[Spice-devel] [win-vdagent PATCH] vdagent: protect against NULL entry in _displays

Uri Lublin uril at redhat.com
Tue Apr 30 03:10:19 PDT 2013


rhbz#958051

It may be that a _displays entry will be NULL.
I encountered it when running with multiple QXL devices, for one of
which the driver failed to load since it was "out of resources"

Iterations over _displays should handle that case.
I found three such iterations, and fixed them in this patch
---
 vdagent/desktop_layout.cpp |    3 +++
 vdagent/vdagent.cpp        |    9 ++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index c474edb..7dadc9a 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -155,6 +155,9 @@ void DesktopLayout::normalize_displays_pos()
 
     for (iter = _displays.begin(); iter != _displays.end(); iter++) {
         mode = *iter;
+        if (!mode) {
+            continue;
+        }
         if (mode->_attached) {
             min_x = min(min_x, mode->_pos_x);
             min_y = min(min_y, mode->_pos_y);
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index dde967c..3423aa1 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -613,7 +613,9 @@ bool VDAgent::handle_mon_config(VDAgentMonitorsConfig* mon_config, uint32_t port
     display_count = _desktop_layout->get_display_count();
     for (uint32_t i = 0; i < display_count; i++) {
         DisplayMode* mode = _desktop_layout->get_display(i);
-        ASSERT(mode);
+        if (!mode) {
+            continue;
+        }
         if (i >= mon_config->num_of_monitors) {
             vd_printf("%d. detached", i);
             mode->set_attached(false);
@@ -738,8 +740,9 @@ void VDAgent::set_display_depth(uint32_t depth)
     // setting depth for all the monitors, including unattached ones
     for (uint32_t i = 0; i < display_count; i++) {
         DisplayMode* mode = _desktop_layout->get_display(i);
-        ASSERT(mode);
-        mode->set_depth(depth);
+        if (mode) {
+            mode->set_depth(depth);
+        }
     }
 
     if (display_count) {
-- 
1.7.1



More information about the Spice-devel mailing list