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
This commit is contained in:
Philip Withnall 2023-08-16 16:24:26 +01:00
parent eae5c49085
commit 9f6b77d835

View File

@ -3966,10 +3966,22 @@ distribute_signals (GDBusConnection *connection,
GDBusMessage *message) GDBusMessage *message)
{ {
GPtrArray *signal_data_array; 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); 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 ())) if (G_UNLIKELY (_g_dbus_debug_signal ()))
{ {
_g_dbus_debug_print_lock (); _g_dbus_debug_print_lock ();
@ -3978,9 +3990,7 @@ distribute_signals (GDBusConnection *connection,
" <<<< RECEIVED SIGNAL %s.%s\n" " <<<< RECEIVED SIGNAL %s.%s\n"
" on object %s\n" " on object %s\n"
" sent by name %s\n", " sent by name %s\n",
g_dbus_message_get_interface (message), interface, member, path,
g_dbus_message_get_member (message),
g_dbus_message_get_path (message),
sender != NULL ? sender : "(none)"); sender != NULL ? sender : "(none)");
_g_dbus_debug_print_unlock (); _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); 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); member = g_dbus_message_get_member (message);
path = g_dbus_message_get_path (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); subtree_path = g_strdup (path);
needle = strrchr (subtree_path, '/'); needle = strrchr (subtree_path, '/');
if (needle != NULL && needle != subtree_path) if (needle != NULL && needle != subtree_path)
@ -7210,7 +7228,6 @@ distribute_method_call (GDBusConnection *connection,
subtree_path = NULL; subtree_path = NULL;
} }
if (G_UNLIKELY (_g_dbus_debug_incoming ())) if (G_UNLIKELY (_g_dbus_debug_incoming ()))
{ {
_g_dbus_debug_print_lock (); _g_dbus_debug_print_lock ();