mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
fuzz: Abort when using global PRNG without re-seed
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <test/fuzz/util/check_globals.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/check.h>
|
||||
@@ -78,6 +79,12 @@ void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target,
|
||||
static std::string_view g_fuzz_target;
|
||||
static const TypeTestOneInput* g_test_one_input{nullptr};
|
||||
|
||||
inline void test_one_input(FuzzBufferType buffer)
|
||||
{
|
||||
CheckGlobals check{};
|
||||
(*Assert(g_test_one_input))(buffer);
|
||||
}
|
||||
|
||||
const std::function<std::string()> G_TEST_GET_FULL_NAME{[]{
|
||||
return std::string{g_fuzz_target};
|
||||
}};
|
||||
@@ -210,7 +217,6 @@ void signal_handler(int signal)
|
||||
// This function is used by libFuzzer
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
static const auto& test_one_input = *Assert(g_test_one_input);
|
||||
test_one_input({data, size});
|
||||
return 0;
|
||||
}
|
||||
@@ -227,7 +233,6 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
initialize();
|
||||
static const auto& test_one_input = *Assert(g_test_one_input);
|
||||
#ifdef __AFL_LOOP
|
||||
// Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
|
||||
// See fuzzing.md for details.
|
||||
|
||||
Reference in New Issue
Block a user