diff options
-rw-r--r-- | base/rand_util.h | 3 | ||||
-rw-r--r-- | chrome/browser/history/delete_directive_handler.cc | 11 | ||||
-rw-r--r-- | sync/internal_api/write_node.cc | 1 |
3 files changed, 13 insertions, 2 deletions
diff --git a/base/rand_util.h b/base/rand_util.h index bae8c31..6130c12 100644 --- a/base/rand_util.h +++ b/base/rand_util.h @@ -39,10 +39,11 @@ BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits); // See crypto/ for cryptographically secure random number generation APIs. BASE_EXPORT void RandBytes(void* output, size_t output_length); -// Fills a string of length |length| with with random data and returns it. +// Fills a string of length |length| with random data and returns it. // |length| should be nonzero. // // Note that this is a variation of |RandBytes| with a different return type. +// The returned string is likely not ASCII/UTF-8. Use with care. // // WARNING: // Do not use for security-sensitive purposes. diff --git a/chrome/browser/history/delete_directive_handler.cc b/chrome/browser/history/delete_directive_handler.cc index c08bf77..9c7d24e 100644 --- a/chrome/browser/history/delete_directive_handler.cc +++ b/chrome/browser/history/delete_directive_handler.cc @@ -18,6 +18,15 @@ namespace { +std::string RandASCIIString(size_t length) { + std::string result; + const int kMin = static_cast<int>(' '); + const int kMax = static_cast<int>('~'); + for (size_t i = 0; i < length; ++i) + result.push_back(static_cast<char>(base::RandInt(kMin, kMax))); + return result; +} + std::string DeleteDirectiveToString( const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { scoped_ptr<base::DictionaryValue> value( @@ -354,7 +363,7 @@ syncer::SyncError DeleteDirectiveHandler::ProcessLocalDeleteDirective( // Generate a random sync tag since history delete directives don't // have a 'built-in' ID. 8 bytes should suffice. - std::string sync_tag = base::RandBytesAsString(8); + std::string sync_tag = RandASCIIString(8); sync_pb::EntitySpecifics entity_specifics; entity_specifics.mutable_history_delete_directive()->CopyFrom( delete_directive); diff --git a/sync/internal_api/write_node.cc b/sync/internal_api/write_node.cc index c3ef081..cefd6df 100644 --- a/sync/internal_api/write_node.cc +++ b/sync/internal_api/write_node.cc @@ -57,6 +57,7 @@ void WriteNode::SetTitle(const std::string& title) { if (type != BOOKMARKS && needs_encryption) { new_legal_title = kEncryptedString; } else { + DCHECK(base::IsStringUTF8(title)); SyncAPINameToServerName(title, &new_legal_title); base::TruncateUTF8ToByteSize(new_legal_title, 255, &new_legal_title); } |