[Spice-devel] [spice-gtk v2] usb-device-widget: Fix crash on no USB devices

Victor Toso victortoso at redhat.com
Fri Apr 13 08:50:48 UTC 2018


From: goldengdeng <907246009 at qq.com>

The spice_usb_device_manager_get_devices() is only checking for NULL
while the program can crash when no USB devices are available.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/usb-device-widget.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c
index a3c0910..1be80ae 100644
--- a/src/usb-device-widget.c
+++ b/src/usb-device-widget.c
@@ -218,8 +218,9 @@ static void spice_usb_device_widget_constructed(GObject *gobject)
                      G_CALLBACK(device_error_cb), self);
 
     devices = spice_usb_device_manager_get_devices(priv->manager);
-    if (!devices)
+    if (devices == NULL || devices->len == 0) {
         goto end;
+    }
 
     for (i = 0; i < devices->len; i++)
         device_added_cb(NULL, g_ptr_array_index(devices, i), self);
-- 
2.16.2



More information about the Spice-devel mailing list