Skip to content

Commit dc5333d

Browse files
author
MarcoFalke
committed
Merge #18938: tests: Fill fuzzing coverage gaps for functions in consensus/validation.h, primitives/block.h and util/translation.h
cd34038 Switch from Optional<T> to std::optional<T> (C++17). Run clang-format. (practicalswift) fb559c1 tests: Fill fuzzing coverage gaps for functions in util/translation.h (practicalswift) b74f3d6 tests: Fill fuzzing coverage gaps for functions in consensus/validation.h (practicalswift) c0bbf81 tests: Fill fuzzing coverage gaps for functions in primitives/block.h (practicalswift) Pull request description: * Fill fuzzing coverage gaps for functions in `consensus/validation.h` * Fill fuzzing coverage gaps for functions in `primitives/block.h` * Fill fuzzing coverage gaps for functions in `util/translation.h` * Switch from `Optional<T>` to `std::optional<T>` (C++17). Run `clang-format`. See [`doc/fuzzing.md`](https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md) for information on how to fuzz Bitcoin Core. Don't forget to contribute any coverage increasing inputs you find to the [Bitcoin Core fuzzing corpus repo](https://github.com/bitcoin-core/qa-assets). Happy fuzzing :) Top commit has no ACKs. Tree-SHA512: d6aa4634c3953ade173589a8239bd230eb317ef897835a8557acb73df01b25e5e17bf46f837838e59ec04c1f3d3b7d1309ba68c8a264d17b938215512c9e6085
2 parents f8123d4 + cd34038 commit dc5333d

28 files changed

+158
-87
lines changed

src/test/fuzz/addrdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <addrdb.h>
6-
#include <optional.h>
76
#include <test/fuzz/FuzzedDataProvider.h>
87
#include <test/fuzz/fuzz.h>
98
#include <test/fuzz/util.h>
109

1110
#include <cassert>
1211
#include <cstdint>
12+
#include <optional>
1313
#include <string>
1414
#include <vector>
1515

@@ -30,7 +30,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3030
})};
3131
break;
3232
case 2: {
33-
const Optional<CBanEntry> ban_entry = ConsumeDeserializable<CBanEntry>(fuzzed_data_provider);
33+
const std::optional<CBanEntry> ban_entry = ConsumeDeserializable<CBanEntry>(fuzzed_data_provider);
3434
if (ban_entry) {
3535
return *ban_entry;
3636
}

src/test/fuzz/asmap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ static const std::vector<bool> IPV4_PREFIX_ASMAP = {
2323
true, true, false, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, // Match 0x00
2424
true, true, false, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, // Match 0x00
2525
true, true, false, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, // Match 0x00
26-
true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, // Match 0xFF
27-
true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true // Match 0xFF
26+
true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, // Match 0xFF
27+
true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true // Match 0xFF
2828
};
2929

3030
void test_one_input(const std::vector<uint8_t>& buffer)

src/test/fuzz/asmap_direct.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <util/asmap.h>
65
#include <test/fuzz/fuzz.h>
6+
#include <util/asmap.h>
77

88
#include <cstdint>
99
#include <optional>
@@ -34,7 +34,9 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3434
if (SanityCheckASMap(asmap, buffer.size() - 1 - sep_pos)) {
3535
// Verify that for valid asmaps, no prefix (except up to 7 zero padding bits) is valid.
3636
std::vector<bool> asmap_prefix = asmap;
37-
while (!asmap_prefix.empty() && asmap_prefix.size() + 7 > asmap.size() && asmap_prefix.back() == false) asmap_prefix.pop_back();
37+
while (!asmap_prefix.empty() && asmap_prefix.size() + 7 > asmap.size() && asmap_prefix.back() == false) {
38+
asmap_prefix.pop_back();
39+
}
3840
while (!asmap_prefix.empty()) {
3941
asmap_prefix.pop_back();
4042
assert(!SanityCheckASMap(asmap_prefix, buffer.size() - 1 - sep_pos));

src/test/fuzz/block.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3838
const Consensus::Params& consensus_params = Params().GetConsensus();
3939
BlockValidationState validation_state_pow_and_merkle;
4040
const bool valid_incl_pow_and_merkle = CheckBlock(block, validation_state_pow_and_merkle, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ true);
41+
assert(validation_state_pow_and_merkle.IsValid() || validation_state_pow_and_merkle.IsInvalid() || validation_state_pow_and_merkle.IsError());
42+
(void)validation_state_pow_and_merkle.Error("");
4143
BlockValidationState validation_state_pow;
4244
const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ false);
45+
assert(validation_state_pow.IsValid() || validation_state_pow.IsInvalid() || validation_state_pow.IsError());
4346
BlockValidationState validation_state_merkle;
4447
const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ true);
48+
assert(validation_state_merkle.IsValid() || validation_state_merkle.IsInvalid() || validation_state_merkle.IsError());
4549
BlockValidationState validation_state_none;
4650
const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ false);
51+
assert(validation_state_none.IsValid() || validation_state_none.IsInvalid() || validation_state_none.IsError());
4752
if (valid_incl_pow_and_merkle) {
4853
assert(valid_incl_pow && valid_incl_merkle && valid_incl_none);
4954
} else if (valid_incl_merkle || valid_incl_pow) {

src/test/fuzz/block_header.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <optional.h>
65
#include <primitives/block.h>
76
#include <test/fuzz/FuzzedDataProvider.h>
87
#include <test/fuzz/fuzz.h>
@@ -11,13 +10,14 @@
1110

1211
#include <cassert>
1312
#include <cstdint>
13+
#include <optional>
1414
#include <string>
1515
#include <vector>
1616

1717
void test_one_input(const std::vector<uint8_t>& buffer)
1818
{
1919
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
20-
const Optional<CBlockHeader> block_header = ConsumeDeserializable<CBlockHeader>(fuzzed_data_provider);
20+
const std::optional<CBlockHeader> block_header = ConsumeDeserializable<CBlockHeader>(fuzzed_data_provider);
2121
if (!block_header) {
2222
return;
2323
}
@@ -38,4 +38,12 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3838
block.SetNull();
3939
assert(block.GetBlockHeader().GetHash() == mut_block_header.GetHash());
4040
}
41+
{
42+
std::optional<CBlockLocator> block_locator = ConsumeDeserializable<CBlockLocator>(fuzzed_data_provider);
43+
if (block_locator) {
44+
(void)block_locator->IsNull();
45+
block_locator->SetNull();
46+
assert(block_locator->IsNull());
47+
}
48+
}
4149
}

src/test/fuzz/blockfilter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <blockfilter.h>
6-
#include <optional.h>
76
#include <test/fuzz/FuzzedDataProvider.h>
87
#include <test/fuzz/fuzz.h>
98
#include <test/fuzz/util.h>
109

1110
#include <cstdint>
11+
#include <optional>
1212
#include <string>
1313
#include <vector>
1414

1515
void test_one_input(const std::vector<uint8_t>& buffer)
1616
{
1717
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
18-
const Optional<BlockFilter> block_filter = ConsumeDeserializable<BlockFilter>(fuzzed_data_provider);
18+
const std::optional<BlockFilter> block_filter = ConsumeDeserializable<BlockFilter>(fuzzed_data_provider);
1919
if (!block_filter) {
2020
return;
2121
}

src/test/fuzz/bloom_filter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <bloom.h>
6-
#include <optional.h>
76
#include <primitives/transaction.h>
87
#include <test/fuzz/FuzzedDataProvider.h>
98
#include <test/fuzz/fuzz.h>
@@ -12,6 +11,7 @@
1211

1312
#include <cassert>
1413
#include <cstdint>
14+
#include <optional>
1515
#include <string>
1616
#include <vector>
1717

@@ -35,7 +35,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3535
break;
3636
}
3737
case 1: {
38-
const Optional<COutPoint> out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
38+
const std::optional<COutPoint> out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
3939
if (!out_point) {
4040
break;
4141
}
@@ -46,7 +46,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
4646
break;
4747
}
4848
case 2: {
49-
const Optional<uint256> u256 = ConsumeDeserializable<uint256>(fuzzed_data_provider);
49+
const std::optional<uint256> u256 = ConsumeDeserializable<uint256>(fuzzed_data_provider);
5050
if (!u256) {
5151
break;
5252
}
@@ -57,7 +57,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
5757
break;
5858
}
5959
case 3: {
60-
const Optional<CMutableTransaction> mut_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
60+
const std::optional<CMutableTransaction> mut_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
6161
if (!mut_tx) {
6262
break;
6363
}

src/test/fuzz/chain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <chain.h>
6-
#include <optional.h>
76
#include <test/fuzz/FuzzedDataProvider.h>
87
#include <test/fuzz/fuzz.h>
98
#include <test/fuzz/util.h>
109

1110
#include <cstdint>
11+
#include <optional>
1212
#include <vector>
1313

1414
void test_one_input(const std::vector<uint8_t>& buffer)
1515
{
1616
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
17-
Optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);
17+
std::optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);
1818
if (!disk_block_index) {
1919
return;
2020
}

src/test/fuzz/checkqueue.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <checkqueue.h>
6-
#include <optional.h>
76
#include <test/fuzz/FuzzedDataProvider.h>
87
#include <test/fuzz/fuzz.h>
98
#include <test/fuzz/util.h>

src/test/fuzz/cuckoocache.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <cuckoocache.h>
6-
#include <optional.h>
76
#include <script/sigcache.h>
87
#include <test/fuzz/FuzzedDataProvider.h>
98
#include <test/fuzz/fuzz.h>

0 commit comments

Comments
 (0)