Index: net/quic/crypto/source_address_token.cc |
diff --git a/net/quic/crypto/source_address_token.cc b/net/quic/crypto/source_address_token.cc |
index d15afebf2a75557f30c6a9a3b724c7cfc1193c44..b095e762265f758aa2d2c9be40d5488fd8a255b5 100644 |
--- a/net/quic/crypto/source_address_token.cc |
+++ b/net/quic/crypto/source_address_token.cc |
@@ -21,24 +21,36 @@ SourceAddressToken::~SourceAddressToken() { |
} |
string SourceAddressToken::SerializeAsString() const { |
- return ip_ + " " + base::Int64ToString(timestamp_); |
+ string out; |
+ out.push_back(ip_.size()); |
+ out.append(ip_); |
+ string time_str = base::Int64ToString(timestamp_); |
+ out.push_back(time_str.size()); |
+ out.append(time_str); |
+ return out; |
} |
bool SourceAddressToken::ParseFromArray(const char* plaintext, |
size_t plaintext_length) { |
- string data(plaintext, plaintext_length); |
- vector<string> results; |
- base::SplitString(data, ' ', &results); |
- if (results.size() < 2) { |
+ if (plaintext_length == 0) { |
+ return false; |
+ } |
+ size_t ip_len = plaintext[0]; |
+ if (plaintext_length <= 1 + ip_len) { |
+ return false; |
+ } |
+ size_t time_len = plaintext[1 + ip_len]; |
+ if (plaintext_length != 1 + ip_len + 1 + time_len) { |
return false; |
} |
+ string time_str(&plaintext[1 + ip_len + 1], time_len); |
int64 timestamp; |
- if (!base::StringToInt64(results[1], ×tamp)) { |
+ if (!base::StringToInt64(time_str, ×tamp)) { |
return false; |
} |
- ip_ = results[0]; |
+ ip_.assign(&plaintext[1], ip_len); |
timestamp_ = timestamp; |
return true; |
} |