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