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

Unified Diff: net/http/http_response_headers.cc

Issue 8760010: Ensure HttpResponseHeaders::raw_headers_ always ends with 2 '\0' characters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed tests Created 9 years, 1 month 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_response_headers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 691536b3bbd11e104d5129db7d91985e497c8be2..f249db88e236a4ea4ddd03f0397e401a046f71ea 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -390,9 +390,13 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) {
(line_end + 1) != raw_input.end() &&
*(line_end + 1) != '\0');
ParseStatusLine(line_begin, line_end, has_headers);
+ raw_headers_.push_back('\0'); // Terminate status line with a null.
if (line_end == raw_input.end()) {
- raw_headers_.push_back('\0');
+ raw_headers_.push_back('\0'); // Ensure the headers end with a double null.
+
+ DCHECK_EQ('\0', raw_headers_[raw_headers_.size() - 2]);
+ DCHECK_EQ('\0', raw_headers_[raw_headers_.size() - 1]);
return;
}
@@ -403,6 +407,13 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) {
// it (to populate our parsed_ vector).
raw_headers_.append(line_end + 1, raw_input.end());
+ // Ensure the headers end with a double null.
+ while (raw_headers_.size() < 2 ||
+ raw_headers_[raw_headers_.size() - 2] != '\0' ||
+ raw_headers_[raw_headers_.size() - 1] != '\0') {
+ raw_headers_.push_back('\0');
+ }
+
// Adjust to point at the null byte following the status line
line_end = raw_headers_.begin() + status_line_len - 1;
@@ -414,6 +425,9 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) {
headers.values_begin(),
headers.values_end());
}
+
+ DCHECK_EQ('\0', raw_headers_[raw_headers_.size() - 2]);
+ DCHECK_EQ('\0', raw_headers_[raw_headers_.size() - 1]);
}
// Append all of our headers to the final output string.
@@ -663,7 +677,6 @@ void HttpResponseHeaders::ParseStatusLine(
if (p == line_end) {
DVLOG(1) << "missing response status; assuming 200 OK";
raw_headers_.append(" 200 OK");
- raw_headers_.push_back('\0');
response_code_ = 200;
return;
}
@@ -703,8 +716,6 @@ void HttpResponseHeaders::ParseStatusLine(
} else {
raw_headers_.append(p, line_end);
}
-
- raw_headers_.push_back('\0');
}
size_t HttpResponseHeaders::FindHeader(size_t from,
« no previous file with comments | « net/http/http_response_headers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698