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

Side by Side Diff: net/url_request/url_request_data_job_fuzzer.cc

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: rebased Created 4 years, 3 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 read_loop_ = nullptr; 92 read_loop_ = nullptr;
93 return 0; 93 return 0;
94 } 94 }
95 95
96 void QuitLoop() { 96 void QuitLoop() {
97 DCHECK(read_loop_); 97 DCHECK(read_loop_);
98 task_runner_->PostTask(FROM_HERE, read_loop_->QuitClosure()); 98 task_runner_->PostTask(FROM_HERE, read_loop_->QuitClosure());
99 } 99 }
100 100
101 void ReadFromRequest(net::URLRequest* request) { 101 void ReadFromRequest(net::URLRequest* request) {
102 bool sync = false; 102 int bytes_read = 0;
103 do { 103 do {
104 // If possible, pop the next read size. If none exists, then this should 104 // If possible, pop the next read size. If none exists, then this should
105 // be the last call to Read. 105 // be the last call to Read.
106 bool using_populated_read = read_lengths_.size() > 0; 106 bool using_populated_read = read_lengths_.size() > 0;
107 size_t read_size = 1; 107 size_t read_size = 1;
108 if (using_populated_read) { 108 if (using_populated_read) {
109 read_size = read_lengths_.back(); 109 read_size = read_lengths_.back();
110 read_lengths_.pop_back(); 110 read_lengths_.pop_back();
111 } 111 }
112 112
113 int bytes_read = 0; 113 bytes_read = request->Read(buf_.get(), read_size);
114 sync = request->Read(buf_.get(), read_size, &bytes_read); 114 } while (bytes_read > 0);
115 } while (sync);
116 115
117 if (!request->status().is_io_pending()) 116 if (bytes_read != net::ERR_IO_PENDING)
118 QuitLoop(); 117 QuitLoop();
119 } 118 }
120 119
121 // net::URLRequest::Delegate: 120 // net::URLRequest::Delegate:
122 void OnReceivedRedirect(net::URLRequest* request, 121 void OnReceivedRedirect(net::URLRequest* request,
123 const net::RedirectInfo& redirect_info, 122 const net::RedirectInfo& redirect_info,
124 bool* defer_redirect) override {} 123 bool* defer_redirect) override {}
125 void OnAuthRequired(net::URLRequest* request, 124 void OnAuthRequired(net::URLRequest* request,
126 net::AuthChallengeInfo* auth_info) override {} 125 net::AuthChallengeInfo* auth_info) override {}
127 void OnCertificateRequested( 126 void OnCertificateRequested(
128 net::URLRequest* request, 127 net::URLRequest* request,
129 net::SSLCertRequestInfo* cert_request_info) override {} 128 net::SSLCertRequestInfo* cert_request_info) override {}
130 void OnSSLCertificateError(net::URLRequest* request, 129 void OnSSLCertificateError(net::URLRequest* request,
131 const net::SSLInfo& ssl_info, 130 const net::SSLInfo& ssl_info,
132 bool fatal) override {} 131 bool fatal) override {}
133 void OnResponseStarted(net::URLRequest* request) override { 132 void OnResponseStarted(net::URLRequest* request, int net_error) override {
134 DCHECK(!request->status().is_io_pending());
135 DCHECK(buf_.get()); 133 DCHECK(buf_.get());
136 DCHECK(read_loop_); 134 DCHECK(read_loop_);
137 if (request->status().is_success()) { 135 DCHECK_NE(net::ERR_IO_PENDING, net_error);
136
137 if (net_error == net::OK) {
138 ReadFromRequest(request); 138 ReadFromRequest(request);
139 } else { 139 } else {
140 QuitLoop(); 140 QuitLoop();
141 } 141 }
142 } 142 }
143 void OnReadCompleted(net::URLRequest* request, int bytes_read) override { 143 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {
144 DCHECK(!request->status().is_io_pending()); 144 DCHECK_NE(net::ERR_IO_PENDING, bytes_read);
145 DCHECK(buf_.get()); 145 DCHECK(buf_.get());
146 DCHECK(read_loop_); 146 DCHECK(read_loop_);
147 if (request->status().is_success() && bytes_read > 0) { 147
148 if (bytes_read > 0) {
148 ReadFromRequest(request); 149 ReadFromRequest(request);
149 } else { 150 } else {
150 QuitLoop(); 151 QuitLoop();
151 } 152 }
152 } 153 }
153 154
154 private: 155 private:
155 friend struct base::DefaultSingletonTraits<URLRequestDataJobFuzzerHarness>; 156 friend struct base::DefaultSingletonTraits<URLRequestDataJobFuzzerHarness>;
156 157
157 net::TestURLRequestContext context_; 158 net::TestURLRequestContext context_;
158 net::URLRequestJobFactoryImpl job_factory_; 159 net::URLRequestJobFactoryImpl job_factory_;
159 std::vector<size_t> read_lengths_; 160 std::vector<size_t> read_lengths_;
160 scoped_refptr<net::IOBuffer> buf_; 161 scoped_refptr<net::IOBuffer> buf_;
161 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 162 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
162 base::RunLoop* read_loop_; 163 base::RunLoop* read_loop_;
163 164
164 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness); 165 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness);
165 }; 166 };
166 167
167 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 168 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
168 // Using a static singleton test harness lets the test run ~3-4x faster. 169 // Using a static singleton test harness lets the test run ~3-4x faster.
169 return URLRequestDataJobFuzzerHarness::GetInstance() 170 return URLRequestDataJobFuzzerHarness::GetInstance()
170 ->CreateAndReadFromDataURLRequest(data, size); 171 ->CreateAndReadFromDataURLRequest(data, size);
171 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698