gdbus: Fix replying to messages marked with NOREPLY flag
Luiz Augusto von Dentz
maintainerPATCH 1/2 gdbus: Fix replying to messages marked with NOREPLY flag
From: Luiz Augusto von Dentz <[email protected]>
When a sender flags a D-Bus message as not expecting a reply, it is against D-Bus policy to send a reply — sending one can result in an error as reported in:
https://bugzilla.kernel.org/show_bug.cgi?id=198453
--- gdbus/object.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
gdbus/object.c +10 -7
@@ -1421,6 +1421,10 @@ DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name, {char str[1024 ]; +/* Check if the message can be replied */ +if (dbus_message_get_no_reply (message)) +return NULL ; +if (format)vsnprintf (str,sizeof (str), format, args);else
@@ -1449,6 +1453,10 @@ DBusMessage *g_dbus_create_reply_valist(DBusMessage *message, {DBusMessage *reply; +/* Check if the message can be replied */ +if (dbus_message_get_no_reply (message)) +return NULL ; + reply =dbus_message_new_method_return (message);if (reply ==NULL )return NULL ;
@@ -1571,14 +1579,9 @@ gboolean g_dbus_send_reply_valist(DBusConnection *connection, {DBusMessage *reply; - reply =dbus_message_new_method_return (message); -if (reply ==NULL ) -return FALSE; - -if (dbus_message_append_args_valist (reply, type, args) == FALSE) { -dbus_message_unref (reply); + reply =g_dbus_create_reply_valist (message, type, args); +if (!reply)return FALSE; - }return g_dbus_send_message (connection, reply); }
Signature · 1 line
2.14.3
Luiz Augusto von Dentz
maintainerPATCH 2/2 gdbus: Fail to send NULL messages
From: Luiz Augusto von Dentz <[email protected]>
This should make it safe to call g_dbus_send_message with a NULL message which is more likely to happen now that g_dbus_create_reply returns NULL when the message is marked with NO_REPLY flag.
--- gdbus/object.c | 3 +++ 1 file changed, 3 insertions(+)
gdbus/object.c +3 -0
@@ -1502,6 +1502,9 @@ gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message) {dbus_bool_t result = FALSE; +if (!message) +return FALSE; +if (dbus_message_get_type (message) ==DBUS_MESSAGE_TYPE_METHOD_CALL )dbus_message_set_no_reply (message, TRUE);else if (dbus_message_get_type (message) ==DBUS_MESSAGE_TYPE_SIGNAL ) {
Signature · 1 line
2.14.3
Luiz Augusto von Dentz
maintainerHi,
Quoted 4 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
When a sender flags a D-Bus message as not expecting a reply, it is against D-Bus policy to send a reply =E2=80=94 sending one can result in =
an
gdbus/object.c DBusMessage *g_dbus_create_error_valist(DBusMessag=
Quoted 12 lines
error as reported in:
https://bugzilla.kernel.org/show_bug.cgi?id=3D198453
--- gdbus/object.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)gdbus/object.c +0
-0@@ -1421,6 +1421,10 @@ DBusMessage *g_dbus_create_error_valist(DBusMessag=
e *message, const char *name,
gdbus/object.c DBusMessage *g_dbus_create_reply_valist(DBusMessag=
Quoted 11 lines
gdbus/object.c +4
-0{char str[1024 ]; +/* Check if the message can be replied */ +if (dbus_message_get_no_reply (message)) +return NULL ; +if (format)vsnprintf (str,sizeof (str), format, args);else @@ -1449,6 +1453,10 @@ DBusMessage *g_dbus_create_reply_valist(DBusMessag=
e *message,
gdbus/object.c gboolean g_dbus_send_reply_valist(DBusConnection *=
Quoted 11 lines
gdbus/object.c +4
-0{DBusMessage *reply; +/* Check if the message can be replied */ +if (dbus_message_get_no_reply (message)) +return NULL ; + reply =3D dbus_message_new_method_return(message); if (reply =3D=3D NULL)return NULL ;@@ -1571,14 +1579,9 @@ gboolean g_dbus_send_reply_valist(DBusConnection *=
connection,
gdbus/object.c gboolean g_dbus_send_reply_valist(DBusConnection *connection,
Quoted 8 lines
gdbus/object.c +0
-5{DBusMessage *reply; - reply =3D dbus_message_new_method_return(message); - if (reply =3D=3D NULL) - return FALSE; - - if (dbus_message_append_args_valist(reply, type, args) =3D=3D FAL=
SE) {
Quoted 10 lines
gdbus/object.c +2
-3-dbus_message_unref (reply); + reply =3D g_dbus_create_reply_valist(message, type, args); +if (!reply)return FALSE; - }return g_dbus_send_message (connection, reply); } --2.14.3
Pushed.
--=20
Luiz Augusto von Dentz