Chromium Code Reviews| Index: components/dns_prefetch/common/prefetch_messages.cc |
| diff --git a/components/dns_prefetch/common/prefetch_messages.cc b/components/dns_prefetch/common/prefetch_messages.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec4f1d5ad67bd67449f2fe06ea68f5e295202bb7 |
| --- /dev/null |
| +++ b/components/dns_prefetch/common/prefetch_messages.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/dns_prefetch/common/prefetch_messages.h" |
| + |
| +#include "base/strings/string_number_conversions.h" |
| +#include "components/dns_prefetch/common/prefetch_common.h" |
| + |
| +namespace IPC { |
| + |
| +void ParamTraits<dns_prefetch::LookupRequest>::Write( |
| + Message* m, const dns_prefetch::LookupRequest& request) { |
| + IPC::WriteParam(m, request.hostname_list); |
| +} |
| + |
| +bool ParamTraits<dns_prefetch::LookupRequest>::Read( |
| + const Message* m, |
| + PickleIterator* iter, |
| + dns_prefetch::LookupRequest* request) { |
| + // Verify the hostname limits after deserialization success. |
| + if (IPC::ReadParam(m, iter, &request->hostname_list)) { |
| + dns_prefetch::NameList& hostnames = request->hostname_list; |
| + if (hostnames.size() > dns_prefetch::kMaxDnsHostnamesPerRequest) |
| + return false; |
| + |
| + for (const auto& hostname : hostnames) { |
| + if (hostname.length() > dns_prefetch::kMaxDnsHostnameLength) |
|
palmer
2014/10/31 18:46:23
There's more to a hostname's validity than its len
|
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +void ParamTraits<dns_prefetch::LookupRequest>::Log( |
| + const dns_prefetch::LookupRequest& p, std::string* l) { |
| + l->append("<dns_prefetch::LookupRequest: "); |
| + l->append(base::UintToString(p.hostname_list.size())); |
| + l->append(" hostnames>"); |
| +} |
| + |
| +} // namespace IPC |