Commit 3818dd0a authored by thestig@chromium.org's avatar thestig@chromium.org

Sync: Do not generate non-UTF8 names for delete directives.

BUG=371184

Review URL: https://codereview.chromium.org/273283002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270035 0039d316-1c4b-4281-b951-d872f2087c98
parent 4807d16a
......@@ -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.
......
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment