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

Side by Side Diff: net/base/sdch_manager.cc

Issue 1871383005: Fix parsing of max-age in SdchManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improve comment with rdsmith's suggestion Created 4 years, 8 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
« no previous file with comments | « no previous file | net/base/sdch_manager_unittest.cc » ('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 "net/base/sdch_manager.h" 5 #include "net/base/sdch_manager.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 std::string value(dictionary_text, value_start, line_end - value_start); 369 std::string value(dictionary_text, value_start, line_end - value_start);
370 name = base::ToLowerASCII(name); 370 name = base::ToLowerASCII(name);
371 if (name == "domain") { 371 if (name == "domain") {
372 domain = value; 372 domain = value;
373 } else if (name == "path") { 373 } else if (name == "path") {
374 path = value; 374 path = value;
375 } else if (name == "format-version") { 375 } else if (name == "format-version") {
376 if (value != "1.0") 376 if (value != "1.0")
377 return SDCH_DICTIONARY_UNSUPPORTED_VERSION; 377 return SDCH_DICTIONARY_UNSUPPORTED_VERSION;
378 } else if (name == "max-age") { 378 } else if (name == "max-age") {
379 int64_t seconds; 379 // max-age must be a non-negative number. If it is very large saturate
380 // TODO(eroman): crbug.com/596541 -- should not accept a leading +. 380 // to 2^32 - 1. If it is invalid then treat it as expired.
381 base::StringToInt64(value, &seconds); 381 // TODO(eroman): crbug.com/602691 be stricter on failure.
382 expiration = base::Time::Now() + base::TimeDelta::FromSeconds(seconds); 382 uint32_t seconds = std::numeric_limits<uint32_t>::max();
383 ParseIntError parse_int_error;
384 if (ParseUint32(value, &seconds, &parse_int_error) ||
385 parse_int_error == ParseIntError::FAILED_OVERFLOW) {
386 expiration =
387 base::Time::Now() + base::TimeDelta::FromSeconds(seconds);
388 } else {
389 expiration = base::Time();
390 }
383 } else if (name == "port") { 391 } else if (name == "port") {
392 // TODO(eroman): crbug.com/602691 be stricter on failure.
384 int port; 393 int port;
385 if (ParseInt32(value, ParseIntFormat::NON_NEGATIVE, &port)) 394 if (ParseInt32(value, ParseIntFormat::NON_NEGATIVE, &port))
386 ports.insert(port); 395 ports.insert(port);
387 } 396 }
388 } 397 }
389 398
390 if (line_end >= header_end) 399 if (line_end >= header_end)
391 break; 400 break;
392 line_start = line_end + 1; 401 line_start = line_end + 1;
393 } 402 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 entry_dict->SetInteger("tries", it->second.count); 483 entry_dict->SetInteger("tries", it->second.count);
475 entry_dict->SetInteger("reason", it->second.reason); 484 entry_dict->SetInteger("reason", it->second.reason);
476 entry_list->Append(std::move(entry_dict)); 485 entry_list->Append(std::move(entry_dict));
477 } 486 }
478 value->Set("blacklisted", std::move(entry_list)); 487 value->Set("blacklisted", std::move(entry_list));
479 488
480 return std::move(value); 489 return std::move(value);
481 } 490 }
482 491
483 } // namespace net 492 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/sdch_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698