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

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

Issue 1946793002: net: Add fuzzer for HostResolverImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Suppress leak 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/base/fuzzed_data_provider.h" 5 #include "net/base/fuzzed_data_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 offset += 8; 47 offset += 8;
48 } 48 }
49 49
50 // Avoid division by 0, in the case |range + 1| results in overflow. 50 // Avoid division by 0, in the case |range + 1| results in overflow.
51 if (range == std::numeric_limits<uint32_t>::max()) 51 if (range == std::numeric_limits<uint32_t>::max())
52 return result; 52 return result;
53 53
54 return min + result % (range + 1); 54 return min + result % (range + 1);
55 } 55 }
56 56
57 int FuzzedDataProvider::ConsumeValueInRangeInt(int min, int max) {
58 CHECK_LE(min, max);
59
60 uint32_t range = max - min;
61 return min + ConsumeValueInRange(0, range);
62 }
63
57 bool FuzzedDataProvider::ConsumeBool() { 64 bool FuzzedDataProvider::ConsumeBool() {
58 return (ConsumeUint8() & 0x01) == 0x01; 65 return (ConsumeUint8() & 0x01) == 0x01;
59 } 66 }
60 67
61 uint8_t FuzzedDataProvider::ConsumeUint8() { 68 uint8_t FuzzedDataProvider::ConsumeUint8() {
62 return ConsumeValueInRange(0, 0xFF); 69 return ConsumeValueInRange(0, 0xFF);
63 } 70 }
64 71
65 uint16_t FuzzedDataProvider::ConsumeUint16() { 72 uint16_t FuzzedDataProvider::ConsumeUint16() {
66 return ConsumeValueInRange(0, 0xFFFF); 73 return ConsumeValueInRange(0, 0xFFFF);
67 } 74 }
68 75
69 } // namespace net 76 } // namespace net
OLDNEW
« no previous file with comments | « net/base/fuzzed_data_provider.h ('k') | net/data/dns/dns.dict » ('j') | net/data/dns/dns.dict » ('J')

Powered by Google App Engine
This is Rietveld 408576698