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

Side by Side Diff: components/cronet/android/url_request_adapter.cc

Issue 1732493002: Prevent URLFetcher::AppendChunkedData from dereferencing NULL pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused variable Created 4 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 | « components/cronet/android/url_request_adapter.h ('k') | net/base/chunked_upload_data_stream.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/cronet/android/url_request_adapter.h" 5 #include "components/cronet/android/url_request_adapter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 void URLRequestAdapter::Start() { 122 void URLRequestAdapter::Start() {
123 context_->PostTaskToNetworkThread( 123 context_->PostTaskToNetworkThread(
124 FROM_HERE, 124 FROM_HERE,
125 base::Bind(&URLRequestAdapter::OnInitiateConnection, 125 base::Bind(&URLRequestAdapter::OnInitiateConnection,
126 base::Unretained(this))); 126 base::Unretained(this)));
127 } 127 }
128 128
129 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes, 129 void URLRequestAdapter::OnAppendChunk(const scoped_ptr<char[]> bytes,
130 int bytes_len, bool is_last_chunk) { 130 int bytes_len, bool is_last_chunk) {
131 DCHECK(OnNetworkThread()); 131 DCHECK(OnNetworkThread());
132 // Request could have completed and been destroyed on the network thread 132 // If AppendData returns false, the request has been cancelled or completed
133 // while appendChunk was posting the task from an application thread. 133 // without uploading the entire request body. Either way, that result will
134 if (!url_request_) { 134 // have been sent to the embedder, so there's nothing else to do here.
135 VLOG(1) << "Cannot append chunk to destroyed request: " 135 chunked_upload_writer_->AppendData(bytes.get(), bytes_len, is_last_chunk);
136 << url_.possibly_invalid_spec().c_str();
137 return;
138 }
139 url_request_->AppendChunkToUpload(bytes.get(), bytes_len, is_last_chunk);
140 } 136 }
141 137
142 void URLRequestAdapter::OnInitiateConnection() { 138 void URLRequestAdapter::OnInitiateConnection() {
143 DCHECK(OnNetworkThread()); 139 DCHECK(OnNetworkThread());
144 if (canceled_) { 140 if (canceled_) {
145 return; 141 return;
146 } 142 }
147 143
148 VLOG(1) << "Starting chromium request: " 144 VLOG(1) << "Starting chromium request: "
149 << url_.possibly_invalid_spec().c_str() 145 << url_.possibly_invalid_spec().c_str()
150 << " priority: " << RequestPriorityToString(priority_); 146 << " priority: " << RequestPriorityToString(priority_);
151 url_request_ = context_->GetURLRequestContext()->CreateRequest( 147 url_request_ = context_->GetURLRequestContext()->CreateRequest(
152 url_, net::DEFAULT_PRIORITY, this); 148 url_, net::DEFAULT_PRIORITY, this);
153 int flags = net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES; 149 int flags = net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES;
154 if (context_->load_disable_cache()) 150 if (context_->load_disable_cache())
155 flags |= net::LOAD_DISABLE_CACHE; 151 flags |= net::LOAD_DISABLE_CACHE;
156 url_request_->SetLoadFlags(flags); 152 url_request_->SetLoadFlags(flags);
157 url_request_->set_method(method_); 153 url_request_->set_method(method_);
158 url_request_->SetExtraRequestHeaders(headers_); 154 url_request_->SetExtraRequestHeaders(headers_);
159 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { 155 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) {
160 std::string user_agent; 156 std::string user_agent;
161 user_agent = context_->GetUserAgent(url_); 157 user_agent = context_->GetUserAgent(url_);
162 url_request_->SetExtraRequestHeaderByName( 158 url_request_->SetExtraRequestHeaderByName(
163 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); 159 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */);
164 } 160 }
165 161
166 if (upload_data_stream_) { 162 if (upload_data_stream_) {
167 url_request_->set_upload(std::move(upload_data_stream_)); 163 url_request_->set_upload(std::move(upload_data_stream_));
168 } else if (chunked_upload_) { 164 } else if (chunked_upload_) {
169 url_request_->EnableChunkedUpload(); 165 scoped_ptr<net::ChunkedUploadDataStream> chunked_upload_data_stream(
166 new net::ChunkedUploadDataStream(0));
167 // Create a ChunkedUploadDataStream::Writer, which keeps a weak reference to
168 // the UploadDataStream, before passing ownership of the stream to the
169 // URLRequest.
170 chunked_upload_writer_ = chunked_upload_data_stream->CreateWriter();
171 url_request_->set_upload(std::move(chunked_upload_data_stream));
170 } 172 }
171 173
172 url_request_->SetPriority(priority_); 174 url_request_->SetPriority(priority_);
173 175
174 url_request_->Start(); 176 url_request_->Start();
175 } 177 }
176 178
177 void URLRequestAdapter::Cancel() { 179 void URLRequestAdapter::Cancel() {
178 context_->PostTaskToNetworkThread( 180 context_->PostTaskToNetworkThread(
179 FROM_HERE, 181 FROM_HERE,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 unsigned char* URLRequestAdapter::Data() const { 323 unsigned char* URLRequestAdapter::Data() const {
322 DCHECK(OnNetworkThread()); 324 DCHECK(OnNetworkThread());
323 return reinterpret_cast<unsigned char*>(read_buffer_->data()); 325 return reinterpret_cast<unsigned char*>(read_buffer_->data());
324 } 326 }
325 327
326 bool URLRequestAdapter::OnNetworkThread() const { 328 bool URLRequestAdapter::OnNetworkThread() const {
327 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); 329 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread();
328 } 330 }
329 331
330 } // namespace cronet 332 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/android/url_request_adapter.h ('k') | net/base/chunked_upload_data_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698