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

Unified Diff: net/http/http_request_headers.cc

Issue 2225933004: Avoid adding invalid headers in AddHeaderFromString (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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 | « net/http/http_request_headers.h ('k') | net/http/http_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_request_headers.cc
diff --git a/net/http/http_request_headers.cc b/net/http/http_request_headers.cc
index ec01446ef98a2cd61fad7ab0eca954041ffb53f7..9a6f1b97e1af762908f0748b3e022dec8c1e4f8e 100644
--- a/net/http/http_request_headers.cc
+++ b/net/http/http_request_headers.cc
@@ -132,26 +132,22 @@ void HttpRequestHeaders::AddHeaderFromString(
}
const base::StringPiece header_key(header_line.data(), key_end_index);
+ if (!HttpUtil::IsValidHeaderName(header_key)) {
+ LOG(DFATAL) << "\"" << header_line << "\" has invalid header key.";
+ return;
+ }
const std::string::size_type value_index = key_end_index + 1;
if (value_index < header_line.size()) {
- std::string header_value(header_line.data() + value_index,
- header_line.size() - value_index);
- std::string::const_iterator header_value_begin =
- header_value.begin();
- std::string::const_iterator header_value_end =
- header_value.end();
- HttpUtil::TrimLWS(&header_value_begin, &header_value_end);
-
- if (header_value_begin == header_value_end) {
- // Value was all LWS.
- SetHeader(header_key, "");
- } else {
- SetHeader(header_key,
- base::StringPiece(&*header_value_begin,
- header_value_end - header_value_begin));
+ base::StringPiece header_value(header_line.data() + value_index,
+ header_line.size() - value_index);
+ header_value = HttpUtil::TrimLWS(header_value);
+ if (!HttpUtil::IsValidHeaderValue(header_value)) {
+ LOG(DFATAL) << "\"" << header_line << "\" has invalid header value.";
+ return;
}
+ SetHeader(header_key, header_value);
} else if (value_index == header_line.size()) {
SetHeader(header_key, "");
} else {
« no previous file with comments | « net/http/http_request_headers.h ('k') | net/http/http_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698