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

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

Issue 7796025: Don't interpret embeded NULLs in a response header line as a line terminator. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address wtc comments Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_util.h ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 while (lines.GetNext()) { 540 while (lines.GetNext()) {
541 const char* line_begin = lines.token_begin(); 541 const char* line_begin = lines.token_begin();
542 const char* line_end = lines.token_end(); 542 const char* line_end = lines.token_end();
543 543
544 if (prev_line_continuable && IsLWS(*line_begin)) { 544 if (prev_line_continuable && IsLWS(*line_begin)) {
545 // Join continuation; reduce the leading LWS to a single SP. 545 // Join continuation; reduce the leading LWS to a single SP.
546 raw_headers.push_back(' '); 546 raw_headers.push_back(' ');
547 raw_headers.append(FindFirstNonLWS(line_begin, line_end), line_end); 547 raw_headers.append(FindFirstNonLWS(line_begin, line_end), line_end);
548 } else { 548 } else {
549 // Terminate the previous line. 549 // Terminate the previous line.
550 raw_headers.push_back('\0'); 550 raw_headers.push_back('\n');
551 551
552 // Copy the raw data to output. 552 // Copy the raw data to output.
553 raw_headers.append(line_begin, line_end); 553 raw_headers.append(line_begin, line_end);
554 554
555 // Check if the current line can be continued. 555 // Check if the current line can be continued.
556 prev_line_continuable = IsLineSegmentContinuable(line_begin, line_end); 556 prev_line_continuable = IsLineSegmentContinuable(line_begin, line_end);
557 } 557 }
558 } 558 }
559 559
560 raw_headers.append("\0\0", 2); 560 raw_headers.append("\n\n", 2);
561
562 // Use '\0' as the canonical line terminator. If the input already contained
563 // any embeded '\0' characters we will strip them first to avoid interpreting
564 // them as line breaks.
565 raw_headers.erase(std::remove(raw_headers.begin(), raw_headers.end(), '\0'),
566 raw_headers.end());
567 std::replace(raw_headers.begin(), raw_headers.end(), '\n', '\0');
568
561 return raw_headers; 569 return raw_headers;
562 } 570 }
563 571
564 std::string HttpUtil::ConvertHeadersBackToHTTPResponse(const std::string& str) { 572 std::string HttpUtil::ConvertHeadersBackToHTTPResponse(const std::string& str) {
565 std::string disassembled_headers; 573 std::string disassembled_headers;
566 StringTokenizer tokenizer(str, std::string(1, '\0')); 574 StringTokenizer tokenizer(str, std::string(1, '\0'));
567 while (tokenizer.GetNext()) { 575 while (tokenizer.GetNext()) {
568 disassembled_headers.append(tokenizer.token_begin(), tokenizer.token_end()); 576 disassembled_headers.append(tokenizer.token_begin(), tokenizer.token_end());
569 disassembled_headers.append("\r\n"); 577 disassembled_headers.append("\r\n");
570 } 578 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 value_is_quoted_ = true; 794 value_is_quoted_ = true;
787 // Do not store iterators into this. See declaration of unquoted_value_. 795 // Do not store iterators into this. See declaration of unquoted_value_.
788 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); 796 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_);
789 } 797 }
790 } 798 }
791 799
792 return true; 800 return true;
793 } 801 }
794 802
795 } // namespace net 803 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_util.h ('k') | net/http/http_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698