2019-04-11 09:53:04 -04:00
|
|
|
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
2016-04-22 15:19:33 -07:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2019-06-24 17:22:28 +02:00
|
|
|
#include <addrdb.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <addrman.h>
|
2018-08-13 16:13:29 -04:00
|
|
|
#include <blockencodings.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <chain.h>
|
|
|
|
#include <coins.h>
|
|
|
|
#include <compressor.h>
|
2018-08-13 16:13:29 -04:00
|
|
|
#include <consensus/merkle.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <net.h>
|
2018-08-13 16:13:29 -04:00
|
|
|
#include <primitives/block.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <protocol.h>
|
|
|
|
#include <streams.h>
|
|
|
|
#include <undo.h>
|
|
|
|
#include <version.h>
|
2016-04-22 15:19:33 -07:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2019-01-25 18:35:36 -05:00
|
|
|
#include <test/fuzz/fuzz.h>
|
2016-04-22 15:19:33 -07:00
|
|
|
|
2019-10-07 08:28:01 +00:00
|
|
|
void test_one_input(const std::vector<uint8_t>& buffer)
|
2019-01-25 18:42:21 -05:00
|
|
|
{
|
2016-04-22 15:19:33 -07:00
|
|
|
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
|
|
|
|
try {
|
|
|
|
int nVersion;
|
|
|
|
ds >> nVersion;
|
|
|
|
ds.SetVersion(nVersion);
|
|
|
|
} catch (const std::ios_base::failure& e) {
|
2019-01-25 18:42:21 -05:00
|
|
|
return;
|
2016-04-22 15:19:33 -07:00
|
|
|
}
|
|
|
|
|
2019-01-25 18:35:36 -05:00
|
|
|
#if BLOCK_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CBlock block;
|
|
|
|
ds >> block;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BLOCKLOCATOR_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CBlockLocator bl;
|
|
|
|
ds >> bl;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BLOCKMERKLEROOT
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CBlock block;
|
|
|
|
ds >> block;
|
|
|
|
bool mutated;
|
|
|
|
BlockMerkleRoot(block, &mutated);
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif ADDRMAN_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CAddrMan am;
|
|
|
|
ds >> am;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BLOCKHEADER_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CBlockHeader bh;
|
|
|
|
ds >> bh;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BANENTRY_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CBanEntry be;
|
|
|
|
ds >> be;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif TXUNDO_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CTxUndo tu;
|
|
|
|
ds >> tu;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BLOCKUNDO_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CBlockUndo bu;
|
|
|
|
ds >> bu;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif COINS_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
2017-04-25 11:29:39 -07:00
|
|
|
Coin coin;
|
|
|
|
ds >> coin;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif NETADDR_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CNetAddr na;
|
|
|
|
ds >> na;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif SERVICE_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CService s;
|
|
|
|
ds >> s;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif MESSAGEHEADER_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
CMessageHeader::MessageStartChars pchMessageStart = {0x00, 0x00, 0x00, 0x00};
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CMessageHeader mh(pchMessageStart);
|
|
|
|
ds >> mh;
|
2019-01-25 18:42:21 -05:00
|
|
|
if (!mh.IsValid(pchMessageStart)) {return;}
|
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif ADDRESS_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CAddress a;
|
|
|
|
ds >> a;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif INV_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CInv i;
|
|
|
|
ds >> i;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BLOOMFILTER_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CBloomFilter bf;
|
|
|
|
ds >> bf;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif DISKBLOCKINDEX_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CDiskBlockIndex dbi;
|
|
|
|
ds >> dbi;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif TXOUTCOMPRESSOR_DESERIALIZE
|
2016-04-22 15:19:33 -07:00
|
|
|
CTxOut to;
|
2016-12-15 09:18:31 -08:00
|
|
|
CTxOutCompressor toc(to);
|
2016-04-22 15:19:33 -07:00
|
|
|
try
|
|
|
|
{
|
2016-12-15 09:18:31 -08:00
|
|
|
ds >> toc;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BLOCKTRANSACTIONS_DESERIALIZE
|
2017-10-25 22:08:10 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
BlockTransactions bt;
|
|
|
|
ds >> bt;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2019-01-25 18:35:36 -05:00
|
|
|
#elif BLOCKTRANSACTIONSREQUEST_DESERIALIZE
|
2017-10-25 22:08:10 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
BlockTransactionsRequest btr;
|
|
|
|
ds >> btr;
|
2019-01-25 18:42:21 -05:00
|
|
|
} catch (const std::ios_base::failure& e) {return;}
|
2017-05-18 21:37:31 +02:00
|
|
|
#else
|
2019-01-25 18:35:36 -05:00
|
|
|
#error Need at least one fuzz target to compile
|
2017-05-18 21:37:31 +02:00
|
|
|
#endif
|
|
|
|
}
|