Skip to content

Commit

Permalink
Return error if D-Bus set/get property method is failed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fujiwarat committed Feb 18, 2023
1 parent 2a235c8 commit ecfae16
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 73 deletions.
86 changes: 37 additions & 49 deletions bus/ibusimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1213,9 +1216,6 @@ _ibus_get_current_input_context (BusIBusImpl *ibus,
GError **error)
{
GVariant *retval = NULL;
if (error) {
*error = NULL;
}

if (!ibus->focused_context)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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 (
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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 (
Expand All @@ -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 *
Expand Down
27 changes: 23 additions & 4 deletions bus/inputcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
44 changes: 30 additions & 14 deletions src/ibusengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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 *
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ibusenginesimple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit ecfae16

Please sign in to comment.