diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2023-08-16 16:24:26 +0100 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2023-08-31 11:15:34 +0100 |
commit | 65ea5bde8e0588f8019f3bb4e0f50a2a7c73c127 (patch) | |
tree | 3a4008d90e9709e2b13c83e12eb7bbcb09c9e362 | |
parent | d10e5d30e561104e727728238efebb68ac5ad992 (diff) | |
download | glib-65ea5bde8e0588f8019f3bb4e0f50a2a7c73c127.tar.gz |
gdbusconnection: Add some assertions about required message fields
The fields are fully validated in `validate_headers()` in
`gdbusmessage.c` now, so the connection code should be able to rely on
the required ones being non-`NULL`.
Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
Helps: #3061
-rw-r--r-- | gio/gdbusconnection.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c index bc3c067dc..1ee2ab44f 100644 --- a/gio/gdbusconnection.c +++ b/gio/gdbusconnection.c @@ -3966,10 +3966,22 @@ distribute_signals (GDBusConnection *connection, GDBusMessage *message) { GPtrArray *signal_data_array; - const gchar *sender; + const gchar *sender, *interface, *member, *path; + + g_assert (g_dbus_message_get_message_type (message) == G_DBUS_MESSAGE_TYPE_SIGNAL); sender = g_dbus_message_get_sender (message); + /* all three of these are required, but should have been validated already + * by validate_headers() in gdbusmessage.c */ + interface = g_dbus_message_get_interface (message); + member = g_dbus_message_get_member (message); + path = g_dbus_message_get_path (message); + + g_assert (interface != NULL); + g_assert (member != NULL); + g_assert (path != NULL); + if (G_UNLIKELY (_g_dbus_debug_signal ())) { _g_dbus_debug_print_lock (); @@ -3978,9 +3990,7 @@ distribute_signals (GDBusConnection *connection, " <<<< RECEIVED SIGNAL %s.%s\n" " on object %s\n" " sent by name %s\n", - g_dbus_message_get_interface (message), - g_dbus_message_get_member (message), - g_dbus_message_get_path (message), + interface, member, path, sender != NULL ? sender : "(none)"); _g_dbus_debug_print_unlock (); } @@ -7195,9 +7205,17 @@ distribute_method_call (GDBusConnection *connection, g_assert (g_dbus_message_get_message_type (message) == G_DBUS_MESSAGE_TYPE_METHOD_CALL); - interface_name = g_dbus_message_get_interface (message); + /* these are required, and should have been validated by validate_headers() + * in gdbusmessage.c already */ member = g_dbus_message_get_member (message); path = g_dbus_message_get_path (message); + + g_assert (member != NULL); + g_assert (path != NULL); + + /* this is optional */ + interface_name = g_dbus_message_get_interface (message); + subtree_path = g_strdup (path); needle = strrchr (subtree_path, '/'); if (needle != NULL && needle != subtree_path) @@ -7210,7 +7228,6 @@ distribute_method_call (GDBusConnection *connection, subtree_path = NULL; } - if (G_UNLIKELY (_g_dbus_debug_incoming ())) { _g_dbus_debug_print_lock (); |