mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
merge bitcoin#19143: Add fuzzing harnesses for CAutoFile, CBufferedFile, LoadExternalBlockFile and other FILE* consumers
includes: - ad6c34881dc125c973b6b9ba1daa999d3141b1ae
This commit is contained in:
parent
27eeceac4d
commit
ed5c750fb6
@ -272,6 +272,7 @@ test_fuzz_fuzz_SOURCES = \
|
|||||||
test/fuzz/parse_script.cpp \
|
test/fuzz/parse_script.cpp \
|
||||||
test/fuzz/parse_univalue.cpp \
|
test/fuzz/parse_univalue.cpp \
|
||||||
test/fuzz/policy_estimator.cpp \
|
test/fuzz/policy_estimator.cpp \
|
||||||
|
test/fuzz/policy_estimator_io.cpp \
|
||||||
test/fuzz/pow.cpp \
|
test/fuzz/pow.cpp \
|
||||||
test/fuzz/prevector.cpp \
|
test/fuzz/prevector.cpp \
|
||||||
test/fuzz/primitives_transaction.cpp \
|
test/fuzz/primitives_transaction.cpp \
|
||||||
|
@ -14,7 +14,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
FUZZ_TARGET(policy_estimator)
|
void initialize_policy_estimator()
|
||||||
|
{
|
||||||
|
InitializeFuzzingContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
FUZZ_TARGET_INIT(policy_estimator, initialize_policy_estimator)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
CBlockPolicyEstimator block_policy_estimator;
|
CBlockPolicyEstimator block_policy_estimator;
|
||||||
@ -62,4 +67,10 @@ FUZZ_TARGET(policy_estimator)
|
|||||||
(void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool());
|
(void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool());
|
||||||
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}));
|
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
|
||||||
|
CAutoFile fuzzed_auto_file = fuzzed_auto_file_provider.open();
|
||||||
|
block_policy_estimator.Write(fuzzed_auto_file);
|
||||||
|
block_policy_estimator.Read(fuzzed_auto_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
28
src/test/fuzz/policy_estimator_io.cpp
Normal file
28
src/test/fuzz/policy_estimator_io.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// 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 <policy/fees.h>
|
||||||
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
|
#include <test/fuzz/fuzz.h>
|
||||||
|
#include <test/fuzz/util.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
void initialize_policy_estimator_io()
|
||||||
|
{
|
||||||
|
InitializeFuzzingContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
FUZZ_TARGET_INIT(policy_estimator_io, initialize_policy_estimator_io)
|
||||||
|
{
|
||||||
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
|
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
|
||||||
|
CAutoFile fuzzed_auto_file = fuzzed_auto_file_provider.open();
|
||||||
|
// Re-using block_policy_estimator across runs to avoid costly creation of CBlockPolicyEstimator object.
|
||||||
|
static CBlockPolicyEstimator block_policy_estimator;
|
||||||
|
if (block_policy_estimator.Read(fuzzed_auto_file)) {
|
||||||
|
block_policy_estimator.Write(fuzzed_auto_file);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user