From e5b68fc6ed5a3d5edff713c88e679a48523ddb3f Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Sun, 7 Jun 2009 17:44:26 +0100 Subject: [PATCH] Ensure messages are locked while marshalling. Locking a message has the side-effect of updating the message's length header. Previously, if dbus_message_marshal() was called on an unlocked message, it could yield an invalid message (as discovered by Ben Schwartz in ). --- dbus/dbus-message.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index edae425..b14d78d 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -3941,11 +3941,18 @@ dbus_message_marshal (DBusMessage *msg, int *len_p) { DBusString tmp; + dbus_bool_t was_locked; _dbus_return_val_if_fail (msg != NULL, FALSE); _dbus_return_val_if_fail (marshalled_data_p != NULL, FALSE); _dbus_return_val_if_fail (len_p != NULL, FALSE); - + + /* Ensure the message is locked, to ensure the length header is filled in. */ + was_locked = msg->locked; + + if (!was_locked) + dbus_message_lock (msg); + if (!_dbus_string_init (&tmp)) return FALSE; @@ -3963,10 +3970,18 @@ dbus_message_marshal (DBusMessage *msg, goto fail; _dbus_string_free (&tmp); + + if (!was_locked) + msg->locked = FALSE; + return TRUE; fail: _dbus_string_free (&tmp); + + if (!was_locked) + msg->locked = FALSE; + return FALSE; } -- 1.6.3.1