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

Side by Side Diff: net/http/http_util.cc

Issue 2134083003: Reject line terminators in HttpUtil::IsValidHeaderValue() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from mmenke Created 4 years, 5 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/http/http_util_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 // The rules for parsing content-types were borrowed from Firefox: 5 // The rules for parsing content-types were borrowed from Firefox:
6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834
7 7
8 #include "net/http/http_util.h" 8 #include "net/http/http_util.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 341
342 // static 342 // static
343 bool HttpUtil::IsValidHeaderName(const std::string& name) { 343 bool HttpUtil::IsValidHeaderName(const std::string& name) {
344 // Check whether the header name is RFC 2616-compliant. 344 // Check whether the header name is RFC 2616-compliant.
345 return HttpUtil::IsToken(name); 345 return HttpUtil::IsToken(name);
346 } 346 }
347 347
348 // static 348 // static
349 bool HttpUtil::IsValidHeaderValue(const std::string& value) { 349 bool HttpUtil::IsValidHeaderValue(const std::string& value) {
350 // Just a sanity check: disallow NUL and CRLF. 350 // Just a sanity check: disallow NUL, CR and LF.
351 return value.find('\0') == std::string::npos && 351 return value.find_first_of("\0\r\n", 0, 3) == std::string::npos;
352 value.find("\r\n") == std::string::npos;
353 } 352 }
354 353
355 // static 354 // static
356 std::string HttpUtil::StripHeaders(const std::string& headers, 355 std::string HttpUtil::StripHeaders(const std::string& headers,
357 const char* const headers_to_remove[], 356 const char* const headers_to_remove[],
358 size_t headers_to_remove_len) { 357 size_t headers_to_remove_len) {
359 std::string stripped_headers; 358 std::string stripped_headers;
360 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); 359 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
361 360
362 while (it.GetNext()) { 361 while (it.GetNext()) {
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 return true; 1053 return true;
1055 } 1054 }
1056 1055
1057 bool HttpUtil::NameValuePairsIterator::IsQuote(char c) const { 1056 bool HttpUtil::NameValuePairsIterator::IsQuote(char c) const {
1058 if (strict_quotes_) 1057 if (strict_quotes_)
1059 return c == '"'; 1058 return c == '"';
1060 return HttpUtil::IsQuote(c); 1059 return HttpUtil::IsQuote(c);
1061 } 1060 }
1062 1061
1063 } // namespace net 1062 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698