From 9a38c03fe27d0c8f9a026a24c33a4bd414b04e2d Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 17 Mar 2015 20:58:46 +0000 Subject: [PATCH] Do not crash when there are no devices to return --- src/fu-main.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/fu-main.c b/src/fu-main.c index 1f559af90..ca1efa5f2 100644 --- a/src/fu-main.c +++ b/src/fu-main.c @@ -137,11 +137,20 @@ fu_main_set_status (FuMainPrivate *priv, FuStatus status) * fu_main_device_array_to_variant: **/ static GVariant * -fu_main_device_array_to_variant (FuMainPrivate *priv) +fu_main_device_array_to_variant (FuMainPrivate *priv, GError **error) { GVariantBuilder builder; guint i; + /* no devices */ + if (priv->devices->len == 0) { + g_set_error_literal (error, + FU_ERROR, + FU_ERROR_NOTHING_TO_DO, + "no supported devices"); + return NULL; + } + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); for (i = 0; i < priv->devices->len; i++) { GVariant *tmp; @@ -456,9 +465,14 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender, /* return 'as' */ if (g_strcmp0 (method_name, "GetDevices") == 0) { + _cleanup_error_free_ GError *error = NULL; _cleanup_strv_free_ gchar **devices = NULL; g_debug ("Called %s()", method_name); - val = fu_main_device_array_to_variant (priv); + val = fu_main_device_array_to_variant (priv, &error); + if (val == NULL) { + g_dbus_method_invocation_return_gerror (invocation, error); + return; + } g_dbus_method_invocation_return_value (invocation, val); fu_main_set_status (priv, FU_STATUS_IDLE); return;