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

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

Issue 1919013003: Add fuzzer to test Fuzz URLRequestDataJob (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url_request_fuzzer
Patch Set: self review 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
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/base/fuzzed_data_provider.h" 5 #include "net/base/fuzzed_data_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 20 matching lines...) Expand all
31 uint8_t new_bits = 0; 31 uint8_t new_bits = 0;
32 if (!remaining_data_.empty()) { 32 if (!remaining_data_.empty()) {
33 new_bits = remaining_data_.data()[remaining_data_.length() - 1]; 33 new_bits = remaining_data_.data()[remaining_data_.length() - 1];
34 remaining_data_ = remaining_data_.substr(0, remaining_data_.length() - 1); 34 remaining_data_ = remaining_data_.substr(0, remaining_data_.length() - 1);
35 } 35 }
36 size_t bits_to_add = 8; 36 size_t bits_to_add = 8;
37 if (num_bits > 8) 37 if (num_bits > 8)
38 bits_to_add = num_bits; 38 bits_to_add = num_bits;
39 new_bits &= new_bits & ((1 << bits_to_add) - 1); 39 new_bits &= new_bits & ((1 << bits_to_add) - 1);
40 out = (out << bits_to_add) | new_bits; 40 out = (out << bits_to_add) | new_bits;
41 num_bits -= bits_to_add; 41 num_bits = num_bits > bits_to_add ? num_bits - bits_to_add : 0;
eroman 2016/04/27 00:43:01 Hmm yeah, there does seem to be a bug in the depen
42 } 42 }
43 43
44 return out; 44 return out;
45 } 45 }
46 46
47 bool FuzzedDataProvider::ConsumeBool() { 47 bool FuzzedDataProvider::ConsumeBool() {
48 return !ConsumeBits(1); 48 return !ConsumeBits(1);
49 } 49 }
50 50
51 uint32_t FuzzedDataProvider::ConsumeValueInRange(uint32_t min, uint32_t max) { 51 uint32_t FuzzedDataProvider::ConsumeValueInRange(uint32_t min, uint32_t max) {
(...skipping 11 matching lines...) Expand all
63 } 63 }
64 64
65 // Allow an empty range, unlike ConsumeBits. 65 // Allow an empty range, unlike ConsumeBits.
66 if (needed_bits == 0) 66 if (needed_bits == 0)
67 return min; 67 return min;
68 68
69 return min + ConsumeBits(needed_bits) % (max - min); 69 return min + ConsumeBits(needed_bits) % (max - min);
70 } 70 }
71 71
72 } // namespace net 72 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698