diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2009-06-07 17:44:26 +0100 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2009-07-14 15:40:02 -0400 |
commit | 1c4e856396c8fba0d7958b4e004c5601dbe9d315 (patch) | |
tree | 267d3848e2ea7056ef98ffed70e40cea97145dba | |
parent | f412447c959d2c7b85190c4bbd83486efd9d7710 (diff) | |
download | dbus-1c4e856396c8fba0d7958b4e004c5601dbe9d315.tar.gz |
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 <http://bugs.freedesktop.org/show_bug.cgi?id=19723>).
(cherry picked from commit 9f825271f9106c23fe51ab54abdb5156b7751014)
-rw-r--r-- | dbus/dbus-message.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 62b042e1..b7b5afca 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -4000,6 +4000,7 @@ 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); @@ -4008,6 +4009,12 @@ dbus_message_marshal (DBusMessage *msg, if (!_dbus_string_init (&tmp)) return 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_copy (&(msg->header.data), 0, &tmp, 0)) goto fail; @@ -4022,10 +4029,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; } |