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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/sdch_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/sdch_manager.cc
diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc
index 7f8245cc917e3507cef3b9bae14fad32233aa06f..aff46608b8a374f157e53c5fdb60f5dedc8e8ccc 100644
--- a/net/base/sdch_manager.cc
+++ b/net/base/sdch_manager.cc
@@ -376,11 +376,20 @@ SdchProblemCode SdchManager::AddSdchDictionary(
if (value != "1.0")
return SDCH_DICTIONARY_UNSUPPORTED_VERSION;
} else if (name == "max-age") {
- int64_t seconds;
- // TODO(eroman): crbug.com/596541 -- should not accept a leading +.
- base::StringToInt64(value, &seconds);
- expiration = base::Time::Now() + base::TimeDelta::FromSeconds(seconds);
+ // max-age must be a non-negative number. If it is very large saturate
+ // to 2^32 - 1. If it is invalid then treat it as expired.
+ // TODO(eroman): crbug.com/602691 be stricter on failure.
+ uint32_t seconds = std::numeric_limits<uint32_t>::max();
+ ParseIntError parse_int_error;
+ if (ParseUint32(value, &seconds, &parse_int_error) ||
+ parse_int_error == ParseIntError::FAILED_OVERFLOW) {
+ expiration =
+ base::Time::Now() + base::TimeDelta::FromSeconds(seconds);
+ } else {
+ expiration = base::Time();
+ }
} else if (name == "port") {
+ // TODO(eroman): crbug.com/602691 be stricter on failure.
int port;
if (ParseInt32(value, ParseIntFormat::NON_NEGATIVE, &port))
ports.insert(port);
« 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