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

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

Issue 15688012: net: don't process truncated headers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only enforce this for HTTPS URLs. Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/http_stream_parser.h" 5 #include "net/http/http_stream_parser.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 return result; 534 return result;
535 } 535 }
536 536
537 // Record our best estimate of the 'response time' as the time when we read 537 // Record our best estimate of the 'response time' as the time when we read
538 // the first bytes of the response headers. 538 // the first bytes of the response headers.
539 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED) 539 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED)
540 response_->response_time = base::Time::Now(); 540 response_->response_time = base::Time::Now();
541 541
542 if (result == ERR_CONNECTION_CLOSED) { 542 if (result == ERR_CONNECTION_CLOSED) {
543 // The connection closed before we detected the end of the headers. 543 // The connection closed before we detected the end of the headers.
544 // parse things as well as we can and let the caller decide what to do.
545 if (read_buf_->offset() == 0) { 544 if (read_buf_->offset() == 0) {
546 // The connection was closed before any data was sent. Likely an error 545 // The connection was closed before any data was sent. Likely an error
547 // rather than empty HTTP/0.9 response. 546 // rather than empty HTTP/0.9 response.
548 io_state_ = STATE_DONE; 547 io_state_ = STATE_DONE;
549 return ERR_EMPTY_RESPONSE; 548 return ERR_EMPTY_RESPONSE;
549 } else if (request_->url.SchemeIs("https")) {
Ryan Sleevi 2013/05/29 19:59:33 Seems like we should be looking at SchemeIsSecure
wtc 2013/05/30 00:38:30 Yes, this sounds like a good idea. In fact, I am w
agl 2013/06/03 18:18:29 After discussions with Darin, I only did this for
wtc 2013/06/03 18:36:47 It occurred to me that this file, http_stream_pars
550 // The connection was closed in the middle of the headers. For HTTPS we
551 // don't parse partial headers. Return a different error code so that we
wtc 2013/05/30 00:38:30 By "a different error code", do you mean an error
agl 2013/06/03 18:18:29 Yes, will clarify.
552 // know that we shouldn't attempt to retry the request.
553 io_state_ = STATE_DONE;
554 return ERR_HEADERS_TRUNCATED;
555 }
556 // Parse things as well as we can and let the caller decide what to do.
557 int end_offset;
558 if (response_header_start_offset_ >= 0) {
559 io_state_ = STATE_READ_BODY_COMPLETE;
560 end_offset = read_buf_->offset();
550 } else { 561 } else {
551 int end_offset; 562 io_state_ = STATE_BODY_PENDING;
552 if (response_header_start_offset_ >= 0) { 563 end_offset = 0;
553 io_state_ = STATE_READ_BODY_COMPLETE;
554 end_offset = read_buf_->offset();
555 } else {
556 io_state_ = STATE_BODY_PENDING;
557 end_offset = 0;
558 }
559 int rv = DoParseResponseHeaders(end_offset);
560 if (rv < 0)
561 return rv;
562 return result;
563 } 564 }
565 int rv = DoParseResponseHeaders(end_offset);
566 if (rv < 0)
567 return rv;
568 return result;
564 } 569 }
565 570
566 read_buf_->set_offset(read_buf_->offset() + result); 571 read_buf_->set_offset(read_buf_->offset() + result);
567 DCHECK_LE(read_buf_->offset(), read_buf_->capacity()); 572 DCHECK_LE(read_buf_->offset(), read_buf_->capacity());
568 DCHECK_GE(result, 0); 573 DCHECK_GE(result, 0);
569 574
570 int end_of_header_offset = ParseResponseHeaders(); 575 int end_of_header_offset = ParseResponseHeaders();
571 576
572 // Note: -1 is special, it indicates we haven't found the end of headers. 577 // Note: -1 is special, it indicates we haven't found the end of headers.
573 // Anything less than -1 is a net::Error, so we bail out. 578 // Anything less than -1 is a net::Error, so we bail out.
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 request_body->IsInMemory() && 947 request_body->IsInMemory() &&
943 request_body->size() > 0) { 948 request_body->size() > 0) {
944 size_t merged_size = request_headers.size() + request_body->size(); 949 size_t merged_size = request_headers.size() + request_body->size();
945 if (merged_size <= kMaxMergedHeaderAndBodySize) 950 if (merged_size <= kMaxMergedHeaderAndBodySize)
946 return true; 951 return true;
947 } 952 }
948 return false; 953 return false;
949 } 954 }
950 955
951 } // namespace net 956 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698