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

Side by Side Diff: net/base/chunked_upload_data_stream.cc

Issue 1732493002: Prevent URLFetcher::AppendChunkedData from dereferencing NULL pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 9 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 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 "net/base/chunked_upload_data_stream.h" 5 #include "net/base/chunked_upload_data_stream.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 ChunkedUploadDataStream::Writer::~Writer() {}
14
15 bool ChunkedUploadDataStream::Writer::AppendData(const char* data,
16 int data_len,
17 bool is_done) {
18 if (!upload_data_stream_)
19 return false;
20 upload_data_stream_->AppendData(data, data_len, is_done);
21 return true;
22 }
23
24 ChunkedUploadDataStream::Writer::Writer(
25 base::WeakPtr<ChunkedUploadDataStream> upload_data_stream)
26 : upload_data_stream_(upload_data_stream) {}
27
13 ChunkedUploadDataStream::ChunkedUploadDataStream(int64_t identifier) 28 ChunkedUploadDataStream::ChunkedUploadDataStream(int64_t identifier)
14 : UploadDataStream(true, identifier), 29 : UploadDataStream(true, identifier),
15 read_index_(0), 30 read_index_(0),
16 read_offset_(0), 31 read_offset_(0),
17 all_data_appended_(false), 32 all_data_appended_(false),
18 read_buffer_len_(0) { 33 read_buffer_len_(0),
34 weak_factory_(this) {}
35
36 ChunkedUploadDataStream::~ChunkedUploadDataStream() {
19 } 37 }
20 38
21 ChunkedUploadDataStream::~ChunkedUploadDataStream() { 39 scoped_ptr<ChunkedUploadDataStream::Writer>
40 ChunkedUploadDataStream::CreateWriter() {
41 return make_scoped_ptr(new Writer(weak_factory_.GetWeakPtr()));
22 } 42 }
23 43
24 void ChunkedUploadDataStream::AppendData( 44 void ChunkedUploadDataStream::AppendData(
25 const char* data, int data_len, bool is_done) { 45 const char* data, int data_len, bool is_done) {
26 DCHECK(!all_data_appended_); 46 DCHECK(!all_data_appended_);
27 DCHECK(data_len > 0 || is_done); 47 DCHECK(data_len > 0 || is_done);
28 if (data_len > 0) { 48 if (data_len > 0) {
29 DCHECK(data); 49 DCHECK(data);
30 upload_data_.push_back( 50 upload_data_.push_back(
31 make_scoped_ptr(new std::vector<char>(data, data + data_len))); 51 make_scoped_ptr(new std::vector<char>(data, data + data_len)));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // ERR_IO_PENDING. The read will be completed in the next call to AppendData. 113 // ERR_IO_PENDING. The read will be completed in the next call to AppendData.
94 if (bytes_read == 0 && !all_data_appended_) 114 if (bytes_read == 0 && !all_data_appended_)
95 return ERR_IO_PENDING; 115 return ERR_IO_PENDING;
96 116
97 if (read_index_ == upload_data_.size() && all_data_appended_) 117 if (read_index_ == upload_data_.size() && all_data_appended_)
98 SetIsFinalChunk(); 118 SetIsFinalChunk();
99 return bytes_read; 119 return bytes_read;
100 } 120 }
101 121
102 } // namespace net 122 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698