gdbus: Fix replying to messages marked with NOREPLY flag 89/204889/1
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Sun, 28 Jan 2018 13:22:26 +0000 (11:22 -0200)
committerAmit Purwar <amit.purwar@samsung.com>
Mon, 15 Apr 2019 03:22:57 +0000 (08:52 +0530)
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
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
Change-Id: I64f927691a7e135b3855ee2ed10f202f0a1cd632

gdbus/object.c

index bb2ac4c..25fc2db 100755 (executable)
@@ -1488,6 +1488,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
@@ -1516,6 +1520,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;
@@ -1638,14 +1646,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);
 }