Skip to content

Commit db4bd32

Browse files
tests: Skip unnecessary fuzzer initialisation. Hold ECCVerifyHandle only when needed.
1 parent c5ac7af commit db4bd32

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/test/fuzz/deserialize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <net.h>
1313
#include <primitives/block.h>
1414
#include <protocol.h>
15+
#include <pubkey.h>
1516
#include <streams.h>
1617
#include <undo.h>
1718
#include <version.h>
@@ -23,6 +24,12 @@
2324

2425
#include <test/fuzz/fuzz.h>
2526

27+
void initialize()
28+
{
29+
// Fuzzers using pubkey must hold an ECCVerifyHandle.
30+
static const auto verify_handle = MakeUnique<ECCVerifyHandle>();
31+
}
32+
2633
void test_one_input(const std::vector<uint8_t>& buffer)
2734
{
2835
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);

src/test/fuzz/fuzz.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
#include <test/fuzz/fuzz.h>
66

7+
#include <cstdint>
78
#include <unistd.h>
8-
9-
#include <pubkey.h>
10-
#include <util/memory.h>
11-
9+
#include <vector>
1210

1311
static bool read_stdin(std::vector<uint8_t>& data)
1412
{
@@ -23,10 +21,8 @@ static bool read_stdin(std::vector<uint8_t>& data)
2321
}
2422

2523
// Default initialization: Override using a non-weak initialize().
26-
__attribute__((weak))
27-
void initialize()
24+
__attribute__((weak)) void initialize()
2825
{
29-
const static auto verify_handle = MakeUnique<ECCVerifyHandle>();
3026
}
3127

3228
// This function is used by libFuzzer
@@ -50,7 +46,8 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
5046
// the main(...) function.
5147
__attribute__((weak))
5248
#endif
53-
int main(int argc, char **argv)
49+
int
50+
main(int argc, char** argv)
5451
{
5552
initialize();
5653
#ifdef __AFL_INIT

0 commit comments

Comments
 (0)