aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-01-20 08:19:10 -0600
committerTed Gould <ted@gould.cx>2011-01-20 08:19:10 -0600
commit6799278c64cbeef54c962264832d247a3e1b253d (patch)
tree832878218f6dbce80d6ae92efd8ca19ada3d3d52
parent46d3e261e397ff5c89eff13d9df4f20ac46b2cc8 (diff)
parenteb377401158a1c438374a888d4493f637c2b8efe (diff)
downloadlibdbusmenu-6799278c64cbeef54c962264832d247a3e1b253d.tar.gz
libdbusmenu-6799278c64cbeef54c962264832d247a3e1b253d.tar.bz2
libdbusmenu-6799278c64cbeef54c962264832d247a3e1b253d.zip
Fix some crashes when building variants improperly
-rw-r--r--libdbusmenu-glib/server.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c
index 51a47b2..095f333 100644
--- a/libdbusmenu-glib/server.c
+++ b/libdbusmenu-glib/server.c
@@ -907,20 +907,31 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho
g_variant_iter_init(&ids, g_variant_get_child_value(params, 0));
GVariantBuilder builder;
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+ gboolean builder_init = FALSE;
gint id;
while (g_variant_iter_next(&ids, "i", &id)) {
DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id);
if (mi == NULL) continue;
+ if (!builder_init) {
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+ builder_init = TRUE;
+ }
+
GVariantBuilder wbuilder;
g_variant_builder_init(&wbuilder, G_VARIANT_TYPE_TUPLE);
g_variant_builder_add(&wbuilder, "i", id);
GVariant * props = dbusmenu_menuitem_properties_variant(mi);
if (props == NULL) {
- props = g_variant_parse(g_variant_type_new("a{sv}"), "{}", NULL, NULL, NULL);
+ GError * error = NULL;
+ props = g_variant_parse(g_variant_type_new("a{sv}"), "{}", NULL, NULL, &error);
+ if (error != NULL) {
+ g_warning("Unable to parse '{}' as a 'a{sv}': %s", error->message);
+ g_error_free(error);
+ props = NULL;
+ }
}
g_variant_builder_add_value(&wbuilder, props);
@@ -929,11 +940,28 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho
g_variant_builder_add_value(&builder, mi_data);
}
- GVariant * ret = g_variant_builder_end(&builder);
+ GVariant * ret = NULL;
+
+ if (builder_init) {
+ ret = g_variant_builder_end(&builder);
+ } else {
+ GError * error = NULL;
+ ret = g_variant_parse(g_variant_type_new("a(ia(sv))"), "[]", NULL, NULL, NULL);
+ if (error != NULL) {
+ g_warning("Unable to parse '[]' as a 'a(ia(sv))': %s", error->message);
+ g_error_free(error);
+ ret = NULL;
+ }
+ }
- g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE);
- g_variant_builder_add_value(&builder, ret);
- GVariant * final = g_variant_builder_end(&builder);
+ GVariant * final = NULL;
+ if (ret != NULL) {
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE);
+ g_variant_builder_add_value(&builder, ret);
+ final = g_variant_builder_end(&builder);
+ } else {
+ g_warning("Error building property list, final variant is NULL");
+ }
g_dbus_method_invocation_return_value(invocation, final);
@@ -994,7 +1022,13 @@ bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat
ret = g_variant_new("(a(ia{svg}))", g_variant_builder_end(&builder));
} else {
- ret = g_variant_parse(g_variant_type_new("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, NULL);
+ GError * error = NULL;
+ ret = g_variant_parse(g_variant_type_new("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, &error);
+ if (error != NULL) {
+ g_warning("Unable to parse '([(0, {})],)' as a '(a(ia{sv}))': %s", error->message);
+ g_error_free(error);
+ ret = NULL;
+ }
}
g_dbus_method_invocation_return_value(invocation, ret);