Jakub Filak 9e4c23
From 1a9cd8817eb80b2e47a989a1fc5d14292800542e Mon Sep 17 00:00:00 2001
Jakub Filak 9e4c23
From: Jakub Filak <jfilak@redhat.com>
Jakub Filak 9e4c23
Date: Thu, 9 Aug 2012 13:58:49 +0200
Jakub Filak 9e4c23
Subject: [PATCH 3/6] fix abrt-dbus crash if no element is found in GetInfo()
Jakub Filak 9e4c23
Jakub Filak 9e4c23
* g_variant_new() calls g_variant_builder_end() internally
Jakub Filak 9e4c23
Jakub Filak 9e4c23
"...
Jakub Filak 9e4c23
It is also an error to call this function if the builder was created
Jakub Filak 9e4c23
with an indefinite array or maybe type and no children have been added
Jakub Filak 9e4c23
..."
Jakub Filak 9e4c23
[g_variant_builder_end() glib-2.32 documentation]
Jakub Filak 9e4c23
Jakub Filak 9e4c23
Signed-off-by: Jakub Filak <jfilak@redhat.com>
Jakub Filak 9e4c23
---
Jakub Filak 9e4c23
 src/dbus/abrt-dbus.c | 11 +++++++++--
Jakub Filak 9e4c23
 1 file changed, 9 insertions(+), 2 deletions(-)
Jakub Filak 9e4c23
Jakub Filak 9e4c23
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
Jakub Filak 9e4c23
index e4a3689..4302b4f 100644
Jakub Filak 9e4c23
--- a/src/dbus/abrt-dbus.c
Jakub Filak 9e4c23
+++ b/src/dbus/abrt-dbus.c
Jakub Filak 9e4c23
@@ -579,7 +579,7 @@ static void handle_method_call(GDBusConnection *connection,
Jakub Filak 9e4c23
         GList *elements = string_list_from_variant(array);
Jakub Filak 9e4c23
         g_variant_unref(array);
Jakub Filak 9e4c23
 
Jakub Filak 9e4c23
-        GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
Jakub Filak 9e4c23
+        GVariantBuilder *builder = NULL;
Jakub Filak 9e4c23
         for (GList *l = elements; l; l = l->next)
Jakub Filak 9e4c23
         {
Jakub Filak 9e4c23
             const char *element_name = (const char*)l->data;
Jakub Filak 9e4c23
@@ -590,6 +590,9 @@ static void handle_method_call(GDBusConnection *connection,
Jakub Filak 9e4c23
             VERB1 log("element '%s' %s", element_name, value ? "fetched" : "not found");
Jakub Filak 9e4c23
             if (value)
Jakub Filak 9e4c23
             {
Jakub Filak 9e4c23
+                if (!builder)
Jakub Filak 9e4c23
+                    builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
Jakub Filak 9e4c23
+
Jakub Filak 9e4c23
                 /* g_variant_builder_add makes a copy. No need to xstrdup here */
Jakub Filak 9e4c23
                 g_variant_builder_add(builder, "{ss}", element_name, value);
Jakub Filak 9e4c23
                 free(value);
Jakub Filak 9e4c23
@@ -597,8 +600,12 @@ static void handle_method_call(GDBusConnection *connection,
Jakub Filak 9e4c23
         }
Jakub Filak 9e4c23
         list_free_with_free(elements);
Jakub Filak 9e4c23
         dd_close(dd);
Jakub Filak 9e4c23
+        /* It is OK to call g_variant_new("(a{ss})", NULL) because */
Jakub Filak 9e4c23
+        /* G_VARIANT_TYPE_TUPLE allows NULL value */
Jakub Filak 9e4c23
         GVariant *response = g_variant_new("(a{ss})", builder);
Jakub Filak 9e4c23
-        g_variant_builder_unref(builder);
Jakub Filak 9e4c23
+
Jakub Filak 9e4c23
+        if (builder)
Jakub Filak 9e4c23
+            g_variant_builder_unref(builder);
Jakub Filak 9e4c23
 
Jakub Filak 9e4c23
         VERB2 log("GetInfo: returning value for '%s'", problem_dir);
Jakub Filak 9e4c23
         g_dbus_method_invocation_return_value(invocation, response);
Jakub Filak 9e4c23
-- 
Jakub Filak 9e4c23
1.7.11.2
Jakub Filak 9e4c23