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

Side by Side Diff: net/spdy/header_coalescer.cc

Issue 2710053002: HTTP/2 Check header names in HeaderCoalescer (Closed)
Patch Set: fix pseudo and add test Created 3 years, 9 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/spdy/header_coalescer_test.cc » ('j') | net/spdy/header_coalescer_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/spdy/header_coalescer.h" 5 #include "net/spdy/header_coalescer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "net/http/http_util.h"
10 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" 11 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 const size_t kMaxHeaderListSize = 256 * 1024; 15 const size_t kMaxHeaderListSize = 256 * 1024;
15 16
16 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { 17 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) {
17 if (error_seen_) { 18 if (error_seen_) {
18 return; 19 return;
19 } 20 }
20 21
21 if (key.empty()) { 22 if (key.empty()) {
22 DVLOG(1) << "Header name must not be empty."; 23 DVLOG(1) << "Header name must not be empty.";
23 error_seen_ = true; 24 error_seen_ = true;
24 return; 25 return;
25 } 26 }
26 27
28 base::StringPiece key_name = key;
29 if (key[0] == ':') {
30 if (regular_header_seen_) {
31 error_seen_ = true;
32 return;
33 }
34 key_name.remove_prefix(1);
35 } else {
36 regular_header_seen_ = true;
37 }
38
39 if (!HttpUtil::IsValidHeaderName(key_name)) {
40 error_seen_ = true;
41 return;
42 }
43
27 // 32 byte overhead according to RFC 7540 Section 6.5.2. 44 // 32 byte overhead according to RFC 7540 Section 6.5.2.
28 header_list_size_ += key.size() + value.size() + 32; 45 header_list_size_ += key.size() + value.size() + 32;
29 if (header_list_size_ > kMaxHeaderListSize) { 46 if (header_list_size_ > kMaxHeaderListSize) {
30 error_seen_ = true; 47 error_seen_ = true;
31 return; 48 return;
32 } 49 }
33 50
34 if (key[0] == ':') {
35 if (regular_header_seen_) {
36 error_seen_ = true;
37 return;
38 }
39 } else {
40 regular_header_seen_ = true;
41 }
42
43 // End of line delimiter is forbidden according to RFC 7230 Section 3.2. 51 // End of line delimiter is forbidden according to RFC 7230 Section 3.2.
44 // Line folding, RFC 7230 Section 3.2.4., is a special case of this. 52 // Line folding, RFC 7230 Section 3.2.4., is a special case of this.
45 if (value.find("\r\n") != base::StringPiece::npos) { 53 if (value.find("\r\n") != base::StringPiece::npos) {
asanka 2017/02/23 17:45:13 HttpUtil::IsValidHeaderValue(value) According to
xunjieli 2017/02/23 23:07:37 Done.
46 error_seen_ = true; 54 error_seen_ = true;
47 return; 55 return;
48 } 56 }
49 57
50 auto iter = headers_.find(key); 58 auto iter = headers_.find(key);
51 if (iter == headers_.end()) { 59 if (iter == headers_.end()) {
52 headers_[key] = value; 60 headers_[key] = value;
53 } else { 61 } else {
54 // This header had multiple values, so it must be reconstructed. 62 // This header had multiple values, so it must be reconstructed.
55 base::StringPiece v = iter->second; 63 base::StringPiece v = iter->second;
(...skipping 13 matching lines...) Expand all
69 DCHECK(headers_valid_); 77 DCHECK(headers_valid_);
70 headers_valid_ = false; 78 headers_valid_ = false;
71 return std::move(headers_); 79 return std::move(headers_);
72 } 80 }
73 81
74 size_t HeaderCoalescer::EstimateMemoryUsage() const { 82 size_t HeaderCoalescer::EstimateMemoryUsage() const {
75 return SpdyEstimateMemoryUsage(headers_); 83 return SpdyEstimateMemoryUsage(headers_);
76 } 84 }
77 85
78 } // namespace net 86 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/spdy/header_coalescer_test.cc » ('j') | net/spdy/header_coalescer_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698