Explicitly CHECK arguments in dbus::MessageWriter::AppendString/ObjectPath
Add dbus::IsStringValidObjectPath() and dbus::ObjectPath::IsValid()
BUG=129335
TEST=dbus_unittests
Review URL: https://chromiumcodereview.appspot.com/10502011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140489 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/dbus/message.cc b/dbus/message.cc
index 5b45d423..2caf543e 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
+#include "base/string_util.h"
#include "base/stringprintf.h"
#include "dbus/object_path.h"
#include "third_party/protobuf/src/google/protobuf/message_lite.h"
@@ -482,6 +483,8 @@
}
void MessageWriter::AppendString(const std::string& value) {
+ // D-Bus Specification (0.19) says a string "must be valid UTF-8".
+ CHECK(IsStringUTF8(value));
const char* pointer = value.c_str();
AppendBasic(DBUS_TYPE_STRING, &pointer);
// TODO(satorux): It may make sense to return an error here, as the
@@ -490,6 +493,7 @@
}
void MessageWriter::AppendObjectPath(const ObjectPath& value) {
+ CHECK(value.IsValid());
const char* pointer = value.value().c_str();
AppendBasic(DBUS_TYPE_OBJECT_PATH, &pointer);
}