Skip to content

Commit 44444ba

Browse files
author
MarcoFalke
committed
fuzz: Link all targets once
1 parent 751ffaa commit 44444ba

File tree

97 files changed

+434
-1306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+434
-1306
lines changed

doc/fuzzing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $ CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzze
1212
# macOS users: If you have problem with this step then make sure to read "macOS hints for
1313
# libFuzzer" on https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md#macos-hints-for-libfuzzer
1414
$ make
15-
$ src/test/fuzz/process_message
15+
$ FUZZ=process_message src/test/fuzz/fuzz
1616
# abort fuzzing using ctrl-c
1717
```
1818

@@ -26,7 +26,7 @@ If you specify a corpus directory then any new coverage increasing inputs will b
2626

2727
```sh
2828
$ mkdir -p process_message-seeded-from-thin-air/
29-
$ src/test/fuzz/process_message process_message-seeded-from-thin-air/
29+
$ FUZZ=process_message src/test/fuzz/fuzz process_message-seeded-from-thin-air/
3030
INFO: Seed: 840522292
3131
INFO: Loaded 1 modules (424174 inline 8-bit counters): 424174 [0x55e121ef9ab8, 0x55e121f613a6),
3232
INFO: Loaded 1 PC tables (424174 PCs): 424174 [0x55e121f613a8,0x55e1225da288),
@@ -70,7 +70,7 @@ To fuzz `process_message` using the [`bitcoin-core/qa-assets`](https://github.co
7070
7171
```sh
7272
$ git clone https://github.com/bitcoin-core/qa-assets
73-
$ src/test/fuzz/process_message qa-assets/fuzz_seed_corpus/process_message/
73+
$ FUZZ=process_message src/test/fuzz/fuzz qa-assets/fuzz_seed_corpus/process_message/
7474
INFO: Seed: 1346407872
7575
INFO: Loaded 1 modules (424174 inline 8-bit counters): 424174 [0x55d8a9004ab8, 0x55d8a906c3a6),
7676
INFO: Loaded 1 PC tables (424174 PCs): 424174 [0x55d8a906c3a8,0x55d8a96e5288),
@@ -129,7 +129,7 @@ $ make
129129
# try compiling using: AFL_NO_X86=1 make
130130
$ mkdir -p inputs/ outputs/
131131
$ echo A > inputs/thin-air-input
132-
$ afl/afl-fuzz -i inputs/ -o outputs/ -- src/test/fuzz/bech32
132+
$ FUZZ=bech32 afl/afl-fuzz -i inputs/ -o outputs/ -- src/test/fuzz/fuzz
133133
# You may have to change a few kernel parameters to test optimally - afl-fuzz
134134
# will print an error and suggestion if so.
135135
```
@@ -153,7 +153,7 @@ $ cd ..
153153
$ CC=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang CXX=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang++ ./configure --enable-fuzz --with-sanitizers=address,undefined
154154
$ make
155155
$ mkdir -p inputs/
156-
$ honggfuzz/honggfuzz -i inputs/ -- src/test/fuzz/process_message
156+
$ FUZZ=process_message honggfuzz/honggfuzz -i inputs/ -- src/test/fuzz/fuzz
157157
```
158158
159159
Read the [Honggfuzz documentation](https://github.com/google/honggfuzz/blob/master/docs/USAGE.md) for more information.

src/Makefile.test.include

Lines changed: 98 additions & 1087 deletions
Large diffs are not rendered by default.

src/test/fuzz/addition_overflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void TestAdditionOverflow(FuzzedDataProvider& fuzzed_data_provider)
4040
}
4141
} // namespace
4242

43-
void test_one_input(const std::vector<uint8_t>& buffer)
43+
FUZZ_TARGET(addition_overflow)
4444
{
4545
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
4646
TestAdditionOverflow<int64_t>(fuzzed_data_provider);

src/test/fuzz/addrdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <string>
1414
#include <vector>
1515

16-
void test_one_input(const std::vector<uint8_t>& buffer)
16+
FUZZ_TARGET(addrdb)
1717
{
1818
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
1919

src/test/fuzz/addrman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <string>
1818
#include <vector>
1919

20-
void initialize()
20+
void initialize_addrman()
2121
{
2222
SelectParams(CBaseChainParams::REGTEST);
2323
}
@@ -32,7 +32,7 @@ class CAddrManDeterministic : public CAddrMan
3232
}
3333
};
3434

35-
void test_one_input(const std::vector<uint8_t>& buffer)
35+
FUZZ_TARGET_INIT(addrman, initialize_addrman)
3636
{
3737
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
3838
SetMockTime(ConsumeTime(fuzzed_data_provider));

src/test/fuzz/asmap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static const std::vector<bool> IPV4_PREFIX_ASMAP = {
2727
true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true // Match 0xFF
2828
};
2929

30-
void test_one_input(const std::vector<uint8_t>& buffer)
30+
FUZZ_TARGET(asmap)
3131
{
3232
// Encoding: [7 bits: asmap size] [1 bit: ipv6?] [3-130 bytes: asmap] [4 or 16 bytes: addr]
3333
if (buffer.size() < 1 + 3 + 4) return;

src/test/fuzz/asmap_direct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <assert.h>
1313

14-
void test_one_input(const std::vector<uint8_t>& buffer)
14+
FUZZ_TARGET(asmap_direct)
1515
{
1616
// Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte]
1717
std::optional<size_t> sep_pos_opt;

src/test/fuzz/autofile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <string>
1616
#include <vector>
1717

18-
void test_one_input(const std::vector<uint8_t>& buffer)
18+
FUZZ_TARGET(autofile)
1919
{
2020
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
2121
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);

src/test/fuzz/banman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ int64_t ConsumeBanTimeOffset(FuzzedDataProvider& fuzzed_data_provider) noexcept
2424
}
2525
} // namespace
2626

27-
void initialize()
27+
void initialize_banman()
2828
{
2929
InitializeFuzzingContext();
3030
}
3131

32-
void test_one_input(const std::vector<uint8_t>& buffer)
32+
FUZZ_TARGET_INIT(banman, initialize_banman)
3333
{
3434
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
3535
const fs::path banlist_file = GetDataDir() / "fuzzed_banlist.dat";

src/test/fuzz/base_encode_decode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <string>
1515
#include <vector>
1616

17-
void test_one_input(const std::vector<uint8_t>& buffer)
17+
FUZZ_TARGET(base_encode_decode)
1818
{
1919
const std::string random_encoded_string(buffer.begin(), buffer.end());
2020

0 commit comments

Comments
 (0)