Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: dbus/message.cc

Issue 10502011: Explicitly CHECK arguments in dbus::MessageWriter::AppendString/ObjectPath (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/dbus.gyp ('k') | dbus/object_path.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "dbus/message.h" 5 #include "dbus/message.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "dbus/object_path.h" 14 #include "dbus/object_path.h"
14 #include "third_party/protobuf/src/google/protobuf/message_lite.h" 15 #include "third_party/protobuf/src/google/protobuf/message_lite.h"
15 16
16 namespace { 17 namespace {
17 18
18 // Appends the header name and the value to |output|, if the value is 19 // Appends the header name and the value to |output|, if the value is
19 // not empty. 20 // not empty.
20 static void AppendStringHeader(const std::string& header_name, 21 static void AppendStringHeader(const std::string& header_name,
21 const std::string& header_value, 22 const std::string& header_value,
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 476
476 void MessageWriter::AppendUint64(uint64 value) { 477 void MessageWriter::AppendUint64(uint64 value) {
477 AppendBasic(DBUS_TYPE_UINT64, &value); 478 AppendBasic(DBUS_TYPE_UINT64, &value);
478 } 479 }
479 480
480 void MessageWriter::AppendDouble(double value) { 481 void MessageWriter::AppendDouble(double value) {
481 AppendBasic(DBUS_TYPE_DOUBLE, &value); 482 AppendBasic(DBUS_TYPE_DOUBLE, &value);
482 } 483 }
483 484
484 void MessageWriter::AppendString(const std::string& value) { 485 void MessageWriter::AppendString(const std::string& value) {
486 // D-Bus Specification (0.19) says a string "must be valid UTF-8".
487 CHECK(IsStringUTF8(value));
485 const char* pointer = value.c_str(); 488 const char* pointer = value.c_str();
486 AppendBasic(DBUS_TYPE_STRING, &pointer); 489 AppendBasic(DBUS_TYPE_STRING, &pointer);
487 // TODO(satorux): It may make sense to return an error here, as the 490 // TODO(satorux): It may make sense to return an error here, as the
488 // input string can be large. If needed, we could add something like 491 // input string can be large. If needed, we could add something like
489 // bool AppendStringWithErrorChecking(). 492 // bool AppendStringWithErrorChecking().
490 } 493 }
491 494
492 void MessageWriter::AppendObjectPath(const ObjectPath& value) { 495 void MessageWriter::AppendObjectPath(const ObjectPath& value) {
496 CHECK(value.IsValid());
493 const char* pointer = value.value().c_str(); 497 const char* pointer = value.value().c_str();
494 AppendBasic(DBUS_TYPE_OBJECT_PATH, &pointer); 498 AppendBasic(DBUS_TYPE_OBJECT_PATH, &pointer);
495 } 499 }
496 500
497 // Ideally, client shouldn't need to supply the signature string, but 501 // Ideally, client shouldn't need to supply the signature string, but
498 // the underlying D-Bus library requires us to supply this before 502 // the underlying D-Bus library requires us to supply this before
499 // appending contents to array and variant. It's technically possible 503 // appending contents to array and variant. It's technically possible
500 // for us to design API that doesn't require the signature but it will 504 // for us to design API that doesn't require the signature but it will
501 // complicate the implementation so we decided to have the signature 505 // complicate the implementation so we decided to have the signature
502 // parameter. Hopefully, variants are less used in request messages from 506 // parameter. Hopefully, variants are less used in request messages from
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); 956 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd);
953 if (!success) 957 if (!success)
954 return false; 958 return false;
955 959
956 value->PutValue(fd); 960 value->PutValue(fd);
957 // NB: the caller must check validity before using the value 961 // NB: the caller must check validity before using the value
958 return true; 962 return true;
959 } 963 }
960 964
961 } // namespace dbus 965 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/dbus.gyp ('k') | dbus/object_path.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698