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

Side by Side Diff: net/websockets/websocket_channel.cc

Issue 258833005: [WebSocket] Fix a crash caused by a pending empty frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | net/websockets/websocket_channel_test.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/websockets/websocket_channel.h" 5 #include "net/websockets/websocket_channel.h"
6 6
7 #include <limits.h> // for INT_MAX 7 #include <limits.h> // for INT_MAX
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <deque> 10 #include <deque>
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 DCHECK_LE(quota, INT_MAX); 400 DCHECK_LE(quota, INT_MAX);
401 if (!pending_received_frames_.empty()) { 401 if (!pending_received_frames_.empty()) {
402 DCHECK_EQ(0, current_receive_quota_); 402 DCHECK_EQ(0, current_receive_quota_);
403 } 403 }
404 while (!pending_received_frames_.empty() && quota > 0) { 404 while (!pending_received_frames_.empty() && quota > 0) {
405 PendingReceivedFrame& front = pending_received_frames_.front(); 405 PendingReceivedFrame& front = pending_received_frames_.front();
406 const size_t data_size = front.size() - front.offset(); 406 const size_t data_size = front.size() - front.offset();
407 const size_t bytes_to_send = 407 const size_t bytes_to_send =
408 std::min(base::checked_cast<size_t>(quota), data_size); 408 std::min(base::checked_cast<size_t>(quota), data_size);
409 const bool final = front.final() && data_size == bytes_to_send; 409 const bool final = front.final() && data_size == bytes_to_send;
410 const char* data = front.data()->data() + front.offset(); 410 const char* data = front.data() ?
411 front.data()->data() + front.offset() : NULL;
411 const std::vector<char> data_vector(data, data + bytes_to_send); 412 const std::vector<char> data_vector(data, data + bytes_to_send);
Adam Rice 2014/04/28 04:30:08 It would be nice to have a check like if (bytes_t
yhirano 2014/04/28 04:38:16 Done.
412 DVLOG(3) << "Sending frame previously split due to quota to the " 413 DVLOG(3) << "Sending frame previously split due to quota to the "
413 << "renderer: quota=" << quota << " data_size=" << data_size 414 << "renderer: quota=" << quota << " data_size=" << data_size
414 << " bytes_to_send=" << bytes_to_send; 415 << " bytes_to_send=" << bytes_to_send;
415 if (event_interface_->OnDataFrame(final, front.opcode(), data_vector) == 416 if (event_interface_->OnDataFrame(final, front.opcode(), data_vector) ==
416 CHANNEL_DELETED) 417 CHANNEL_DELETED)
417 return; 418 return;
418 if (bytes_to_send < data_size) { 419 if (bytes_to_send < data_size) {
419 front.DidConsume(bytes_to_send); 420 front.DidConsume(bytes_to_send);
420 front.ResetOpcode(); 421 front.ResetOpcode();
421 return; 422 return;
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1064
1064 void WebSocketChannel::CloseTimeout() { 1065 void WebSocketChannel::CloseTimeout() {
1065 stream_->Close(); 1066 stream_->Close();
1066 DCHECK_NE(CLOSED, state_); 1067 DCHECK_NE(CLOSED, state_);
1067 state_ = CLOSED; 1068 state_ = CLOSED;
1068 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); 1069 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""));
1069 // |this| has been deleted. 1070 // |this| has been deleted.
1070 } 1071 }
1071 1072
1072 } // namespace net 1073 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/websockets/websocket_channel_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698