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

Side by Side Diff: net/cookies/cookie_util.cc

Issue 2392873002: Use largest supported date for cookies if timegm overflows
Patch Set: Created 4 years, 2 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 | « base/time/time_posix.cc ('k') | no next file » | 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/cookies/cookie_util.h" 5 #include "net/cookies/cookie_util.h"
6 6
7 #include <cstdio> 7 #include <cstdio>
8 #include <cstdlib> 8 #include <cstdlib>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (exploded.year >= 69 && exploded.year <= 99) 198 if (exploded.year >= 69 && exploded.year <= 99)
199 exploded.year += 1900; 199 exploded.year += 1900;
200 if (exploded.year >= 0 && exploded.year <= 68) 200 if (exploded.year >= 0 && exploded.year <= 68)
201 exploded.year += 2000; 201 exploded.year += 2000;
202 202
203 // If our values are within their correct ranges, we got our time. 203 // If our values are within their correct ranges, we got our time.
204 if (exploded.day_of_month >= 1 && exploded.day_of_month <= 31 && 204 if (exploded.day_of_month >= 1 && exploded.day_of_month <= 31 &&
205 exploded.month >= 1 && exploded.month <= 12 && 205 exploded.month >= 1 && exploded.month <= 12 &&
206 exploded.year >= 1601 && exploded.year <= 30827 && 206 exploded.year >= 1601 && exploded.year <= 30827 &&
207 exploded.hour <= 23 && exploded.minute <= 59 && exploded.second <= 59) { 207 exploded.hour <= 23 && exploded.minute <= 59 && exploded.second <= 59) {
208 return base::Time::FromUTCExploded(exploded); 208 base::Time time;
209 if (!base::Time::FromUTCExploded(exploded, &time)) {
210 if (exploded.year > 1970) {
211 // Overflow occured in the platform time conversion. Let's
212 // used the largest possible time value.
213 time = base::Time::GetMaxPlatformTime();
214 LOG(WARNING) << "Parsed cookie time was clamped to " << time;
215 }
216 }
217 return time;
209 } 218 }
210 219
211 // One of our values was out of expected range. For well-formed input, 220 // One of our values was out of expected range. For well-formed input,
212 // the following check would be reasonable: 221 // the following check would be reasonable:
213 // NOTREACHED() << "Cookie exploded expiration failed: " << time_string; 222 // NOTREACHED() << "Cookie exploded expiration failed: " << time_string;
214 223
215 return base::Time(); 224 return base::Time();
216 } 225 }
217 226
218 GURL CookieOriginToURL(const std::string& domain, bool is_https) { 227 GURL CookieOriginToURL(const std::string& domain, bool is_https) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 buffer.append("; "); 282 buffer.append("; ");
274 buffer.append(i->first.begin(), i->first.end()); 283 buffer.append(i->first.begin(), i->first.end());
275 buffer.push_back('='); 284 buffer.push_back('=');
276 buffer.append(i->second.begin(), i->second.end()); 285 buffer.append(i->second.begin(), i->second.end());
277 } 286 }
278 return buffer; 287 return buffer;
279 } 288 }
280 289
281 } // namespace cookie_util 290 } // namespace cookie_util
282 } // namespace net 291 } // namespace net
OLDNEW
« no previous file with comments | « base/time/time_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698