Ensure HttpResponseHeaders::raw_headers_ always ends with 2 '\0' characters.

BUG=105971
TEST=no


Review URL: http://codereview.chromium.org/8760010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112401 0039d316-1c4b-4281-b951-d872f2087c98
parent aee23654
...@@ -390,9 +390,13 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) { ...@@ -390,9 +390,13 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) {
(line_end + 1) != raw_input.end() && (line_end + 1) != raw_input.end() &&
*(line_end + 1) != '\0'); *(line_end + 1) != '\0');
ParseStatusLine(line_begin, line_end, has_headers); ParseStatusLine(line_begin, line_end, has_headers);
raw_headers_.push_back('\0'); // Terminate status line with a null.
if (line_end == raw_input.end()) { 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; return;
} }
...@@ -403,6 +407,13 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) { ...@@ -403,6 +407,13 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) {
// it (to populate our parsed_ vector). // it (to populate our parsed_ vector).
raw_headers_.append(line_end + 1, raw_input.end()); 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 // Adjust to point at the null byte following the status line
line_end = raw_headers_.begin() + status_line_len - 1; line_end = raw_headers_.begin() + status_line_len - 1;
...@@ -414,6 +425,9 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) { ...@@ -414,6 +425,9 @@ void HttpResponseHeaders::Parse(const std::string& raw_input) {
headers.values_begin(), headers.values_begin(),
headers.values_end()); 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. // Append all of our headers to the final output string.
...@@ -663,7 +677,6 @@ void HttpResponseHeaders::ParseStatusLine( ...@@ -663,7 +677,6 @@ void HttpResponseHeaders::ParseStatusLine(
if (p == line_end) { if (p == line_end) {
DVLOG(1) << "missing response status; assuming 200 OK"; DVLOG(1) << "missing response status; assuming 200 OK";
raw_headers_.append(" 200 OK"); raw_headers_.append(" 200 OK");
raw_headers_.push_back('\0');
response_code_ = 200; response_code_ = 200;
return; return;
} }
...@@ -703,8 +716,6 @@ void HttpResponseHeaders::ParseStatusLine( ...@@ -703,8 +716,6 @@ void HttpResponseHeaders::ParseStatusLine(
} else { } else {
raw_headers_.append(p, line_end); raw_headers_.append(p, line_end);
} }
raw_headers_.push_back('\0');
} }
size_t HttpResponseHeaders::FindHeader(size_t from, size_t HttpResponseHeaders::FindHeader(size_t from,
......
...@@ -278,7 +278,7 @@ class NET_EXPORT HttpResponseHeaders ...@@ -278,7 +278,7 @@ class NET_EXPORT HttpResponseHeaders
// construct a valid one. Example input: // construct a valid one. Example input:
// HTTP/1.1 200 OK // HTTP/1.1 200 OK
// with line_begin and end pointing at the begin and end of this line. // with line_begin and end pointing at the begin and end of this line.
// Output will be a normalized version of this, with a trailing \n. // Output will be a normalized version of this.
void ParseStatusLine(std::string::const_iterator line_begin, void ParseStatusLine(std::string::const_iterator line_begin,
std::string::const_iterator line_end, std::string::const_iterator line_end,
bool has_headers); bool has_headers);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment