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

Side by Side Diff: net/quic/bidirectional_stream_quic_impl.cc

Issue 2032733002: Do not crash on null stream in writing to bidirectional streams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_crash
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/quic/bidirectional_stream_quic_impl.h" 5 #include "net/quic/bidirectional_stream_quic_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // Read will complete asynchronously and Delegate::OnReadCompleted will be 112 // Read will complete asynchronously and Delegate::OnReadCompleted will be
113 // called upon completion. 113 // called upon completion.
114 read_buffer_ = buffer; 114 read_buffer_ = buffer;
115 read_buffer_len_ = buffer_len; 115 read_buffer_len_ = buffer_len;
116 return ERR_IO_PENDING; 116 return ERR_IO_PENDING;
117 } 117 }
118 118
119 void BidirectionalStreamQuicImpl::SendData(const scoped_refptr<IOBuffer>& data, 119 void BidirectionalStreamQuicImpl::SendData(const scoped_refptr<IOBuffer>& data,
120 int length, 120 int length,
121 bool end_stream) { 121 bool end_stream) {
122 DCHECK(stream_);
123 DCHECK(length > 0 || (length == 0 && end_stream)); 122 DCHECK(length > 0 || (length == 0 && end_stream));
124 123
124 if (!stream_) {
125 LOG(ERROR) << "Trying to send data when stream has been destroyed.";
mef 2016/06/01 21:53:15 when -> after
xunjieli 2016/06/01 23:08:22 Done.
126 base::ThreadTaskRunnerHandle::Get()->PostTask(
127 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError,
128 weak_factory_.GetWeakPtr(), ERR_UNEXPECTED));
mef 2016/06/01 21:53:15 nit: Should say ERR_UNEXPECTED in CL description.
xunjieli 2016/06/01 23:08:22 Done.
129 return;
130 }
131
125 std::unique_ptr<QuicConnection::ScopedPacketBundler> bundler; 132 std::unique_ptr<QuicConnection::ScopedPacketBundler> bundler;
126 if (!has_sent_headers_) { 133 if (!has_sent_headers_) {
127 DCHECK(!send_request_headers_automatically_); 134 DCHECK(!send_request_headers_automatically_);
128 // Creates a bundler only if there are headers to be sent along with the 135 // Creates a bundler only if there are headers to be sent along with the
129 // single data buffer. 136 // single data buffer.
130 bundler.reset(new QuicConnection::ScopedPacketBundler( 137 bundler.reset(new QuicConnection::ScopedPacketBundler(
131 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING)); 138 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING));
132 SendRequestHeaders(); 139 SendRequestHeaders();
133 } 140 }
134 141
135 base::StringPiece string_data(data->data(), length); 142 base::StringPiece string_data(data->data(), length);
136 int rv = stream_->WriteStreamData( 143 int rv = stream_->WriteStreamData(
137 string_data, end_stream, 144 string_data, end_stream,
138 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 145 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
139 weak_factory_.GetWeakPtr())); 146 weak_factory_.GetWeakPtr()));
140 DCHECK(rv == OK || rv == ERR_IO_PENDING); 147 DCHECK(rv == OK || rv == ERR_IO_PENDING);
141 if (rv == OK) { 148 if (rv == OK) {
142 base::ThreadTaskRunnerHandle::Get()->PostTask( 149 base::ThreadTaskRunnerHandle::Get()->PostTask(
143 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 150 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
144 weak_factory_.GetWeakPtr(), OK)); 151 weak_factory_.GetWeakPtr(), OK));
145 } 152 }
146 } 153 }
147 154
148 void BidirectionalStreamQuicImpl::SendvData( 155 void BidirectionalStreamQuicImpl::SendvData(
149 const std::vector<scoped_refptr<IOBuffer>>& buffers, 156 const std::vector<scoped_refptr<IOBuffer>>& buffers,
150 const std::vector<int>& lengths, 157 const std::vector<int>& lengths,
151 bool end_stream) { 158 bool end_stream) {
152 DCHECK(stream_);
153 DCHECK_EQ(buffers.size(), lengths.size()); 159 DCHECK_EQ(buffers.size(), lengths.size());
154 160
161 if (!stream_) {
162 LOG(ERROR) << "Trying to send data when stream has been destroyed.";
mef 2016/06/01 21:53:15 when -> after
xunjieli 2016/06/01 23:08:22 Done.
163 base::ThreadTaskRunnerHandle::Get()->PostTask(
164 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError,
165 weak_factory_.GetWeakPtr(), ERR_UNEXPECTED));
166 return;
167 }
168
155 QuicConnection::ScopedPacketBundler bundler( 169 QuicConnection::ScopedPacketBundler bundler(
156 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING); 170 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING);
157 if (!has_sent_headers_) { 171 if (!has_sent_headers_) {
158 DCHECK(!send_request_headers_automatically_); 172 DCHECK(!send_request_headers_automatically_);
159 SendRequestHeaders(); 173 SendRequestHeaders();
160 } 174 }
161 175
162 int rv = stream_->WritevStreamData( 176 int rv = stream_->WritevStreamData(
163 buffers, lengths, end_stream, 177 buffers, lengths, end_stream,
164 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 178 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Spurrious notification. Wait for the next one. 240 // Spurrious notification. Wait for the next one.
227 return; 241 return;
228 } 242 }
229 read_buffer_ = nullptr; 243 read_buffer_ = nullptr;
230 read_buffer_len_ = 0; 244 read_buffer_len_ = 0;
231 delegate_->OnDataRead(rv); 245 delegate_->OnDataRead(rv);
232 } 246 }
233 247
234 void BidirectionalStreamQuicImpl::OnClose(QuicErrorCode error) { 248 void BidirectionalStreamQuicImpl::OnClose(QuicErrorCode error) {
235 DCHECK(stream_); 249 DCHECK(stream_);
250
236 if (error == QUIC_NO_ERROR && 251 if (error == QUIC_NO_ERROR &&
237 stream_->stream_error() == QUIC_STREAM_NO_ERROR) { 252 stream_->stream_error() == QUIC_STREAM_NO_ERROR) {
238 ResetStream(); 253 ResetStream();
239 return; 254 return;
240 } 255 }
241 ResetStream();
mef 2016/06/01 21:53:15 Why no longer ResetStream() here?
xunjieli 2016/06/01 23:08:22 It is redundant. NotifyError will call ResetStream
242 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR 256 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR
243 : ERR_QUIC_HANDSHAKE_FAILED); 257 : ERR_QUIC_HANDSHAKE_FAILED);
244 } 258 }
245 259
246 void BidirectionalStreamQuicImpl::OnError(int error) { 260 void BidirectionalStreamQuicImpl::OnError(int error) {
247 NotifyError(error); 261 NotifyError(error);
248 } 262 }
249 263
250 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() { 264 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() {
251 return has_sent_headers_; 265 return has_sent_headers_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 void BidirectionalStreamQuicImpl::ResetStream() { 312 void BidirectionalStreamQuicImpl::ResetStream() {
299 if (!stream_) 313 if (!stream_)
300 return; 314 return;
301 closed_stream_received_bytes_ = stream_->stream_bytes_read(); 315 closed_stream_received_bytes_ = stream_->stream_bytes_read();
302 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); 316 closed_stream_sent_bytes_ = stream_->stream_bytes_written();
303 stream_->SetDelegate(nullptr); 317 stream_->SetDelegate(nullptr);
304 stream_ = nullptr; 318 stream_ = nullptr;
305 } 319 }
306 320
307 } // namespace net 321 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698