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

Unified Diff: net/spdy/bidirectional_stream_spdy_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, 7 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 side-by-side diff with in-line comments
Download patch
Index: net/spdy/bidirectional_stream_spdy_impl.cc
diff --git a/net/spdy/bidirectional_stream_spdy_impl.cc b/net/spdy/bidirectional_stream_spdy_impl.cc
index a8531d961a5f1ebeb116d2e6554c3de3c435191b..f8a75c349af2729ae7bfd0926d3860ead8354421 100644
--- a/net/spdy/bidirectional_stream_spdy_impl.cc
+++ b/net/spdy/bidirectional_stream_spdy_impl.cc
@@ -60,7 +60,10 @@ void BidirectionalStreamSpdyImpl::Start(
timer_ = std::move(timer);
if (!spdy_session_) {
- delegate_->OnFailed(ERR_CONNECTION_CLOSED);
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&BidirectionalStreamSpdyImpl::NotifyError,
+ weak_factory_.GetWeakPtr(), ERR_CONNECTION_CLOSED));
return;
}
@@ -104,8 +107,15 @@ int BidirectionalStreamSpdyImpl::ReadData(IOBuffer* buf, int buf_len) {
void BidirectionalStreamSpdyImpl::SendData(const scoped_refptr<IOBuffer>& data,
int length,
bool end_stream) {
- DCHECK(!stream_closed_);
- DCHECK(stream_);
+ DCHECK(length > 0 || (length == 0 && end_stream));
+
+ if (!stream_) {
+ LOG(ERROR) << "Trying to send data when stream has been destroyed.";
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&BidirectionalStreamSpdyImpl::NotifyError,
+ weak_factory_.GetWeakPtr(), ERR_UNEXPECTED));
+ return;
+ }
stream_->SendData(data.get(), length,
end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND);
@@ -115,10 +125,16 @@ void BidirectionalStreamSpdyImpl::SendvData(
const std::vector<scoped_refptr<IOBuffer>>& buffers,
const std::vector<int>& lengths,
bool end_stream) {
- DCHECK(!stream_closed_);
- DCHECK(stream_);
DCHECK_EQ(buffers.size(), lengths.size());
+ if (!stream_) {
+ LOG(ERROR) << "Trying to send data when stream has been destroyed.";
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&BidirectionalStreamSpdyImpl::NotifyError,
+ weak_factory_.GetWeakPtr(), ERR_UNEXPECTED));
+ return;
+ }
+
int total_len = 0;
for (int len : lengths) {
total_len += len;
@@ -228,7 +244,7 @@ void BidirectionalStreamSpdyImpl::OnClose(int status) {
stream_.reset();
if (status != OK) {
- delegate_->OnFailed(status);
+ NotifyError(status);
return;
}
// Complete any remaining read, as all data has been buffered.
@@ -267,6 +283,10 @@ void BidirectionalStreamSpdyImpl::OnStreamInitialized(int rv) {
return;
}
}
+ NotifyError(rv);
+}
+
+void BidirectionalStreamSpdyImpl::NotifyError(int rv) {
delegate_->OnFailed(rv);
}
« net/quic/bidirectional_stream_quic_impl.cc ('K') | « net/spdy/bidirectional_stream_spdy_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698