summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfujiwarat <takao.fujiwara1@gmail.com>2023-02-18 19:52:14 +0900
committerfujiwarat <takao.fujiwara1@gmail.com>2023-02-18 19:52:14 +0900
commitecfae1678b117c95264e062deddf9562f902c03d (patch)
tree9066a26fee698327e824db902eae3708d14a90dc
parent2a235c8c33f1de56df4873fe3662d5beb1355715 (diff)
downloadibus-ecfae1678b117c95264e062deddf9562f902c03d.tar.gz
Return error if D-Bus set/get property method is failed
D-Bus set/get property methods are called from GDBusConnection APIs invoke_set_property_in_idle_cb() and invoke_get_property_in_idle_cb() and the error values cannot be null if the methods are failed. BUG=rhbz#2169205
-rw-r--r--bus/ibusimpl.c86
-rw-r--r--bus/inputcontext.c27
-rw-r--r--src/ibusengine.c44
-rw-r--r--src/ibusenginesimple.c2
-rw-r--r--src/ibusservice.c27
5 files changed, 113 insertions, 73 deletions
diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c
index c2ae88df..f2ab2b30 100644
--- a/bus/ibusimpl.c
+++ b/bus/ibusimpl.c
@@ -700,11 +700,14 @@ _ibus_get_address (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
- if (error) {
- *error = NULL;
+ GVariant *retval = g_variant_new_string (bus_server_get_address ());
+ if (!retval) {
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "Cannot get IBus address");
}
-
- return g_variant_new_string (bus_server_get_address ());
+ return retval;
}
static void
@@ -1213,9 +1216,6 @@ _ibus_get_current_input_context (BusIBusImpl *ibus,
GError **error)
{
GVariant *retval = NULL;
- if (error) {
- *error = NULL;
- }
if (!ibus->focused_context)
{
@@ -1359,14 +1359,11 @@ _ibus_get_engines (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
+ GVariant *retval;
GVariantBuilder builder;
GList *engines = NULL;
GList *p;
- if (error) {
- *error = NULL;
- }
-
g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
engines = g_hash_table_get_values (ibus->engine_table);
@@ -1379,7 +1376,9 @@ _ibus_get_engines (BusIBusImpl *ibus,
g_list_free (engines);
- return g_variant_builder_end (&builder);
+ retval = g_variant_builder_end (&builder);
+ g_assert (retval);
+ return retval;
}
static void
@@ -1444,13 +1443,10 @@ _ibus_get_active_engines (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
+ GVariant *retval;
GVariantBuilder builder;
GList *p;
- if (error) {
- *error = NULL;
- }
-
g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
for (p = ibus->register_engine_list; p != NULL; p = p->next) {
@@ -1459,7 +1455,9 @@ _ibus_get_active_engines (BusIBusImpl *ibus,
ibus_serializable_serialize ((IBusSerializable *) p->data));
}
- return g_variant_builder_end (&builder);
+ retval = g_variant_builder_end (&builder);
+ g_assert (retval);
+ return retval;
}
static void
@@ -1528,10 +1526,8 @@ _ibus_get_use_sys_layout (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
- if (error) {
+ if (error)
*error = NULL;
- }
-
return g_variant_new_boolean (ibus->use_sys_layout);
}
@@ -1566,10 +1562,8 @@ _ibus_get_use_global_engine (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
- if (error) {
+ if (error)
*error = NULL;
- }
-
return g_variant_new_boolean (ibus->use_global_engine);
}
@@ -1607,10 +1601,6 @@ _ibus_get_global_engine (BusIBusImpl *ibus,
IBusEngineDesc *desc = NULL;
GVariant *retval = NULL;
- if (error) {
- *error = NULL;
- }
-
do {
if (!ibus->use_global_engine)
break;
@@ -1790,10 +1780,8 @@ _ibus_get_global_engine_enabled (BusIBusImpl *ibus,
{
gboolean enabled = FALSE;
- if (error) {
+ if (error)
*error = NULL;
- }
-
do {
if (!ibus->use_global_engine)
break;
@@ -1849,10 +1837,6 @@ _ibus_set_preload_engines (BusIBusImpl *ibus,
BusFactoryProxy *factory = NULL;
GPtrArray *array = g_ptr_array_new ();
- if (error) {
- *error = NULL;
- }
-
g_variant_get (value, "^a&s", &names);
for (i = 0; names[i] != NULL; i++) {
@@ -1912,11 +1896,9 @@ _ibus_get_embed_preedit_text (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
- if (error) {
- *error = NULL;
- }
-
- return g_variant_new_boolean (ibus->embed_preedit_text);
+ GVariant *retval = g_variant_new_boolean (ibus->embed_preedit_text);
+ g_assert (retval);
+ return retval;
}
/**
@@ -1931,10 +1913,6 @@ _ibus_set_embed_preedit_text (BusIBusImpl *ibus,
GVariant *value,
GError **error)
{
- if (error) {
- *error = NULL;
- }
-
gboolean embed_preedit_text = g_variant_get_boolean (value);
if (embed_preedit_text != ibus->embed_preedit_text) {
ibus->embed_preedit_text = embed_preedit_text;
@@ -2038,6 +2016,8 @@ bus_ibus_impl_service_get_property (IBusService *service,
{ "EmbedPreeditText", _ibus_get_embed_preedit_text },
};
+ if (error)
+ *error = NULL;
if (g_strcmp0 (interface_name, IBUS_INTERFACE_IBUS) != 0) {
return IBUS_SERVICE_CLASS (
bus_ibus_impl_parent_class)->service_get_property (
@@ -2054,9 +2034,12 @@ bus_ibus_impl_service_get_property (IBusService *service,
}
}
- g_warning ("service_get_property received an unknown property: %s",
- property_name ? property_name : "(null)");
- return NULL;
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "service_get_property received an unknown property: %s",
+ property_name ? property_name : "(null)");
+ g_return_val_if_reached (NULL);
}
/**
@@ -2087,6 +2070,8 @@ bus_ibus_impl_service_set_property (IBusService *service,
{ "EmbedPreeditText", _ibus_set_embed_preedit_text },
};
+ if (error)
+ *error = NULL;
if (g_strcmp0 (interface_name, IBUS_INTERFACE_IBUS) != 0) {
return IBUS_SERVICE_CLASS (
bus_ibus_impl_parent_class)->service_set_property (
@@ -2104,9 +2089,12 @@ bus_ibus_impl_service_set_property (IBusService *service,
}
}
- g_warning ("service_set_property received an unknown property: %s",
- property_name ? property_name : "(null)");
- return FALSE;
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "service_set_property received an unknown property: %s",
+ property_name ? property_name : "(null)");
+ g_return_val_if_reached (FALSE);
}
BusIBusImpl *
diff --git a/bus/inputcontext.c b/bus/inputcontext.c
index 72041ecb..e76bbdfc 100644
--- a/bus/inputcontext.c
+++ b/bus/inputcontext.c
@@ -2,7 +2,7 @@
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2008-2014 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright (C) 2015-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (C) 2015-2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -1388,6 +1388,8 @@ bus_input_context_service_set_property (IBusService *service,
GVariant *value,
GError **error)
{
+ if (error)
+ *error = NULL;
if (g_strcmp0 (interface_name, IBUS_INTERFACE_INPUT_CONTEXT) != 0) {
return IBUS_SERVICE_CLASS (bus_input_context_parent_class)->
service_set_property (service,
@@ -1400,10 +1402,22 @@ bus_input_context_service_set_property (IBusService *service,
error);
}
- if (!bus_input_context_service_authorized_method (service, connection))
+ if (!BUS_IS_INPUT_CONTEXT (service)) {
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "%p is not BusInputContext.", service);
return FALSE;
-
- g_return_val_if_fail (BUS_IS_INPUT_CONTEXT (service), FALSE);
+ }
+ if (!bus_input_context_service_authorized_method (service, connection)) {
+ /* No error message due to the security issue but GError is required
+ * by gdbusconnection.c:invoke_set_property_in_idle_cb() */
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ " ");
+ return FALSE;
+ }
if (g_strcmp0 (property_name, "ContentType") == 0) {
_ic_set_content_type (BUS_INPUT_CONTEXT (service), value);
@@ -1414,6 +1428,11 @@ bus_input_context_service_set_property (IBusService *service,
return TRUE;
}
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "service_set_property received an unknown property: %s",
+ property_name ? property_name : "(null)");
g_return_val_if_reached (FALSE);
}
diff --git a/src/ibusengine.c b/src/ibusengine.c
index 8aa27b66..321a58a1 100644
--- a/src/ibusengine.c
+++ b/src/ibusengine.c
@@ -1512,11 +1512,10 @@ _ibus_engine_get_active_surrounding_text (IBusEngine *engine,
GDBusConnection *connection,
GError **error)
{
- if (error) {
- *error = NULL;
- }
-
- return g_variant_new_boolean (engine->priv->has_active_surrounding_text);
+ GVariant *retval = g_variant_new_boolean (
+ engine->priv->has_active_surrounding_text);
+ g_assert (retval);
+ return retval;
}
/**
@@ -1529,11 +1528,9 @@ _ibus_engine_has_focus_id (IBusEngine *engine,
GDBusConnection *connection,
GError **error)
{
- if (error) {
- *error = NULL;
- }
-
- return g_variant_new_boolean (engine->priv->has_focus_id);
+ GVariant *retval = g_variant_new_boolean (engine->priv->has_focus_id);
+ g_assert (retval);
+ return retval;
}
static GVariant *
@@ -1556,6 +1553,8 @@ ibus_engine_service_get_property (IBusService *service,
{ "ActiveSurroundingText", _ibus_engine_get_active_surrounding_text },
};
+ if (error)
+ *error = NULL;
if (g_strcmp0 (interface_name, IBUS_INTERFACE_ENGINE) != 0) {
return IBUS_SERVICE_CLASS (ibus_engine_parent_class)->
service_get_property (service,
@@ -1575,9 +1574,12 @@ ibus_engine_service_get_property (IBusService *service,
}
}
- g_warning ("service_get_property received an unknown property: %s",
- property_name ? property_name : "(null)");
- return NULL;
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "service_get_property received an unknown property: %s",
+ property_name ? property_name : "(null)");
+ g_return_val_if_reached (NULL);
}
static gboolean
@@ -1592,6 +1594,8 @@ ibus_engine_service_set_property (IBusService *service,
{
IBusEngine *engine = IBUS_ENGINE (service);
+ if (error)
+ *error = NULL;
if (g_strcmp0 (interface_name, IBUS_INTERFACE_ENGINE) != 0) {
return IBUS_SERVICE_CLASS (ibus_engine_parent_class)->
service_set_property (service,
@@ -1604,8 +1608,15 @@ ibus_engine_service_set_property (IBusService *service,
error);
}
- if (!ibus_engine_service_authorized_method (service, connection))
+ if (!ibus_engine_service_authorized_method (service, connection)) {
+ /* No error message due to the security issue but GError is required
+ * by gdbusconnection.c:invoke_set_property_in_idle_cb() */
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ " ");
return FALSE;
+ }
if (g_strcmp0 (property_name, "ContentType") == 0) {
guint purpose = 0;
@@ -1629,6 +1640,11 @@ ibus_engine_service_set_property (IBusService *service,
return TRUE;
}
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "service_set_property received an unknown property: %s",
+ property_name ? property_name : "(null)");
g_return_val_if_reached (FALSE);
}
diff --git a/src/ibusenginesimple.c b/src/ibusenginesimple.c
index 3d1668b2..409d5a56 100644
--- a/src/ibusenginesimple.c
+++ b/src/ibusenginesimple.c
@@ -158,7 +158,7 @@ ibus_engine_simple_init (IBusEngineSimple *simple)
G_RESOURCE_LOOKUP_FLAGS_NONE,
&error);
if (error) {
- g_warning ("Nout found compose resource %s", error->message);
+ g_warning ("Not found compose resource %s", error->message);
g_clear_error (&error);
return;
}
diff --git a/src/ibusservice.c b/src/ibusservice.c
index 60255bd5..d207f707 100644
--- a/src/ibusservice.c
+++ b/src/ibusservice.c
@@ -2,7 +2,7 @@
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2008-2015 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright (C) 2015-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (C) 2015-2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2019 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -370,8 +370,9 @@ ibus_service_service_method_call (IBusService *service,
g_dbus_method_invocation_return_error (invocation,
G_DBUS_ERROR,
G_DBUS_ERROR_UNKNOWN_METHOD,
- "%s::%s", interface_name, method_name);
- return;
+ "%s::%s",
+ interface_name, method_name);
+ g_return_if_reached ();
}
static GVariant *
@@ -383,7 +384,15 @@ ibus_service_service_get_property (IBusService *service,
const gchar *property_name,
GError **error)
{
- return NULL;
+ if (error) {
+ *error = NULL;
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "service_get_property received an unknown property: %s",
+ property_name ? property_name : "(null)");
+ }
+ g_return_val_if_reached (NULL);
}
static gboolean
@@ -396,7 +405,15 @@ ibus_service_service_set_property (IBusService *service,
GVariant *value,
GError **error)
{
- return FALSE;
+ if (error) {
+ *error = NULL;
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "service_set_property received an unknown property: %s",
+ property_name ? property_name : "(null)");
+ }
+ g_return_val_if_reached (FALSE);
}
static void