gdbusmessage: Check that message serial is not set to zero

It’s disallowed by the D-Bus specification.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3592
This commit is contained in:
Philip Withnall 2025-02-03 18:31:25 +00:00
parent b94b44407a
commit 8297bbc00c
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -984,10 +984,13 @@ g_dbus_message_get_serial (GDBusMessage *message)
/** /**
* g_dbus_message_set_serial: * g_dbus_message_set_serial:
* @message: A #GDBusMessage. * @message: A #GDBusMessage.
* @serial: A #guint32. * @serial: A #guint32, which must not be zero.
* *
* Sets the serial for @message. * Sets the serial for @message.
* *
* The [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages)
* does not allow the @serial to be zero.
*
* Since: 2.26 * Since: 2.26
*/ */
void void
@ -996,6 +999,10 @@ g_dbus_message_set_serial (GDBusMessage *message,
{ {
g_return_if_fail (G_IS_DBUS_MESSAGE (message)); g_return_if_fail (G_IS_DBUS_MESSAGE (message));
/* As per https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages,
* this must not be zero. */
g_return_if_fail (serial != 0);
if (message->locked) if (message->locked)
{ {
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC); g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);