2020-03-23 10:55:36 -03:00
|
|
|
// Copyright (c) 2020 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <addrdb.h>
|
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <test/fuzz/util.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
2020-05-10 14:35:55 -04:00
|
|
|
#include <optional>
|
2020-03-23 10:55:36 -03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-12-03 12:42:49 -03:00
|
|
|
FUZZ_TARGET(addrdb)
|
2020-03-23 10:55:36 -03:00
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
|
|
|
|
2020-07-19 01:13:16 -04:00
|
|
|
// The point of this code is to exercise all CBanEntry constructors.
|
2020-03-23 10:55:36 -03:00
|
|
|
const CBanEntry ban_entry = [&] {
|
2020-06-10 20:11:38 -04:00
|
|
|
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 2)) {
|
2020-03-23 10:55:36 -03:00
|
|
|
case 0:
|
|
|
|
return CBanEntry{fuzzed_data_provider.ConsumeIntegral<int64_t>()};
|
|
|
|
break;
|
2020-06-10 20:11:38 -04:00
|
|
|
case 1: {
|
2020-05-10 14:35:55 -04:00
|
|
|
const std::optional<CBanEntry> ban_entry = ConsumeDeserializable<CBanEntry>(fuzzed_data_provider);
|
2020-03-23 10:55:36 -03:00
|
|
|
if (ban_entry) {
|
|
|
|
return *ban_entry;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CBanEntry{};
|
|
|
|
}();
|
2020-07-19 01:13:16 -04:00
|
|
|
(void)ban_entry; // currently unused
|
2020-03-23 10:55:36 -03:00
|
|
|
}
|