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

Side by Side Diff: net/socket/fuzzed_socket.cc

Issue 1946793002: net: Add fuzzer for HostResolverImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge, fix build 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 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/socket/fuzzed_socket.h" 5 #include "net/socket/fuzzed_socket.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 DCHECK(!error_pending_); 150 DCHECK(!error_pending_);
151 DCHECK(!total_bytes_read_); 151 DCHECK(!total_bytes_read_);
152 DCHECK(!total_bytes_written_); 152 DCHECK(!total_bytes_written_);
153 153
154 bool sync = true; 154 bool sync = true;
155 Error result = OK; 155 Error result = OK;
156 if (fuzz_connect_result_) { 156 if (fuzz_connect_result_) {
157 // Decide if sync or async. Use async, if no data is left. 157 // Decide if sync or async. Use async, if no data is left.
158 sync = data_provider_->ConsumeBool(); 158 sync = data_provider_->ConsumeBool();
159 // Decide if the connect succeeds or not, and if so, pick an error code. 159 // Decide if the connect succeeds or not, and if so, pick an error code.
160 if (data_provider_->ConsumeBool()) { 160 if (data_provider_->ConsumeBool())
161 result = kConnectErrors[data_provider_->ConsumeValueInRange( 161 result = data_provider_->PickArrayEntry(kConnectErrors);
162 0, arraysize(kConnectErrors) - 1)];
163 }
164 } 162 }
165 163
166 if (sync) { 164 if (sync) {
167 net_error_ = result; 165 net_error_ = result;
168 return result; 166 return result;
169 } 167 }
170 168
171 connect_pending_ = true; 169 connect_pending_ = true;
172 if (result != OK) 170 if (result != OK)
173 error_pending_ = true; 171 error_pending_ = true;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 238
241 void FuzzedSocket::ClearConnectionAttempts() {} 239 void FuzzedSocket::ClearConnectionAttempts() {}
242 240
243 void FuzzedSocket::AddConnectionAttempts(const ConnectionAttempts& attempts) {} 241 void FuzzedSocket::AddConnectionAttempts(const ConnectionAttempts& attempts) {}
244 242
245 int64_t FuzzedSocket::GetTotalReceivedBytes() const { 243 int64_t FuzzedSocket::GetTotalReceivedBytes() const {
246 return total_bytes_read_; 244 return total_bytes_read_;
247 } 245 }
248 246
249 Error FuzzedSocket::ConsumeReadWriteErrorFromData() { 247 Error FuzzedSocket::ConsumeReadWriteErrorFromData() {
250 return kReadWriteErrors[data_provider_->ConsumeValueInRange( 248 return data_provider_->PickArrayEntry(kReadWriteErrors);
251 0, arraysize(kReadWriteErrors) - 1)];
252 } 249 }
253 250
254 void FuzzedSocket::OnReadComplete(const CompletionCallback& callback, 251 void FuzzedSocket::OnReadComplete(const CompletionCallback& callback,
255 int result) { 252 int result) {
256 CHECK(read_pending_); 253 CHECK(read_pending_);
257 read_pending_ = false; 254 read_pending_ = false;
258 if (result <= 0) { 255 if (result <= 0) {
259 error_pending_ = false; 256 error_pending_ = false;
260 } else { 257 } else {
261 total_bytes_read_ += result; 258 total_bytes_read_ += result;
(...skipping 16 matching lines...) Expand all
278 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback, 275 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback,
279 int result) { 276 int result) {
280 CHECK(connect_pending_); 277 CHECK(connect_pending_);
281 connect_pending_ = false; 278 connect_pending_ = false;
282 if (result < 0) 279 if (result < 0)
283 error_pending_ = false; 280 error_pending_ = false;
284 callback.Run(result); 281 callback.Run(result);
285 } 282 }
286 283
287 } // namespace net 284 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698