forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuzz: Abort when using global PRNG without re-seed
- Loading branch information
MarcoFalke
committed
Dec 16, 2024
1 parent
fa7809a
commit fa18acb
Showing
7 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2024-present 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 <test/fuzz/util/check_globals.h> | ||
|
||
#include <test/util/random.h> | ||
|
||
#include <iostream> | ||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
|
||
struct CheckGlobalsImpl { | ||
CheckGlobalsImpl() | ||
{ | ||
g_used_g_prng = false; | ||
g_seeded_g_prng_zero = false; | ||
} | ||
~CheckGlobalsImpl() | ||
{ | ||
if (g_used_g_prng && !g_seeded_g_prng_zero) { | ||
std::cerr << "\n\n" | ||
"The current fuzz target used the global random state.\n\n" | ||
|
||
"This is acceptable, but requires the fuzz target to call \n" | ||
"SeedRandomStateForTest(SeedRand::ZEROS) at the beginning \n" | ||
"of processing the fuzz input.\n\n" | ||
|
||
"An alternative solution would be to avoid any use of globals.\n\n" | ||
|
||
"Without a solution, fuzz stability and determinism can lead \n" | ||
"to non-reproducible bugs or inefficient fuzzing.\n\n" | ||
<< std::endl; | ||
std::abort(); // Abort, because AFL may try to recover from a std::exit | ||
} | ||
} | ||
}; | ||
|
||
CheckGlobals::CheckGlobals() : m_impl(std::make_unique<CheckGlobalsImpl>()) {} | ||
CheckGlobals::~CheckGlobals() = default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2024-present The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_TEST_FUZZ_UTIL_CHECK_GLOBALS_H | ||
#define BITCOIN_TEST_FUZZ_UTIL_CHECK_GLOBALS_H | ||
|
||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
|
||
struct CheckGlobalsImpl; | ||
struct CheckGlobals { | ||
CheckGlobals(); | ||
~CheckGlobals(); | ||
std::unique_ptr<CheckGlobalsImpl> m_impl; | ||
}; | ||
|
||
#endif // BITCOIN_TEST_FUZZ_UTIL_CHECK_GLOBALS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters