aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/util.h
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-06-09 09:45:39 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-07-08 05:05:12 +0000
commitdeba199f1c88c2e5f754b0a4ec43b9ef28de8352 (patch)
treefc46ea1c618c1bf5a1027f18476d5f4133c6ed14 /src/test/fuzz/util.h
parentabdfd2d0e3ebec7dbead89317ee9192189a35809 (diff)
tests: Add ConsumeSubNet(...). Move and increase coverage in ConsumeNetAddr(...).
Diffstat (limited to 'src/test/fuzz/util.h')
-rw-r--r--src/test/fuzz/util.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h
index 1c1b2cd254..704ae80bd8 100644
--- a/src/test/fuzz/util.h
+++ b/src/test/fuzz/util.h
@@ -10,6 +10,7 @@
#include <attributes.h>
#include <coins.h>
#include <consensus/consensus.h>
+#include <netaddress.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <script/standard.h>
@@ -228,4 +229,31 @@ NODISCARD inline std::vector<uint8_t> ConsumeFixedLengthByteVector(FuzzedDataPro
return result;
}
+CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept
+{
+ const Network network = fuzzed_data_provider.PickValueInArray({Network::NET_IPV4, Network::NET_IPV6, Network::NET_INTERNAL, Network::NET_ONION});
+ CNetAddr net_addr;
+ if (network == Network::NET_IPV4) {
+ const in_addr v4_addr = {
+ .s_addr = fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
+ net_addr = CNetAddr{v4_addr};
+ } else if (network == Network::NET_IPV6) {
+ if (fuzzed_data_provider.remaining_bytes() >= 16) {
+ in6_addr v6_addr = {};
+ memcpy(v6_addr.s6_addr, fuzzed_data_provider.ConsumeBytes<uint8_t>(16).data(), 16);
+ net_addr = CNetAddr{v6_addr, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
+ }
+ } else if (network == Network::NET_INTERNAL) {
+ net_addr.SetInternal(fuzzed_data_provider.ConsumeBytesAsString(32));
+ } else if (network == Network::NET_ONION) {
+ net_addr.SetSpecial(fuzzed_data_provider.ConsumeBytesAsString(32));
+ }
+ return net_addr;
+}
+
+CSubNet ConsumeSubNet(FuzzedDataProvider& fuzzed_data_provider) noexcept
+{
+ return {ConsumeNetAddr(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<int32_t>()};
+}
+
#endif // BITCOIN_TEST_FUZZ_UTIL_H