From 9dbc169b4e31feb1426d6e0283cc37edf84a4bb6 Mon Sep 17 00:00:00 2001 From: Ryo Hashimoto Date: Mon, 25 Sep 2017 07:06:14 +0000 Subject: [PATCH] dbus: Always append valid bool values D-Bus spec says bool values other than 1 and 0 are invalid. Although C++'s int->bool conversion converts all values other than 0 to 1, it's still possible to create bool variables with values other than 1 and 0. For example, when a variable is uninitialized, or with code like this: bool b; reinterpret_cast(b) = 10; BUG=767024 TEST=dbus_unittests Change-Id: I225456cb2662cffe992231f8f38a5add0dd2c250 Reviewed-on: https://chromium-review.googlesource.com/678537 Reviewed-by: Dan Erat Commit-Queue: Ryo Hashimoto Cr-Commit-Position: refs/heads/master@{#503995} --- dbus/message.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbus/message.cc b/dbus/message.cc index 9505dbb42d9740..ec0b2234494a8c 100644 --- a/dbus/message.cc +++ b/dbus/message.cc @@ -459,7 +459,7 @@ void MessageWriter::AppendBool(bool value) { // dbus_message_iter_append_basic() used in AppendBasic() expects four // bytes for DBUS_TYPE_BOOLEAN, so we must pass a dbus_bool_t, instead // of a bool, to AppendBasic(). - dbus_bool_t dbus_value = value; + dbus_bool_t dbus_value = value ? 1 : 0; AppendBasic(DBUS_TYPE_BOOLEAN, &dbus_value); }