Skip to content

Commit d00d50e

Browse files
committed
Merge bitcoin#28968: fuzz: Fix nullptr deref in scriptpubkeyman
faecde9 fuzz: Fix nullptr deref in scriptpubkeyman (MarcoFalke) Pull request description: This should fix the UB that was found by review (bitcoin#28578 (comment)) and by fuzzing (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64487) ACKs for top commit: dergoegge: utACK faecde9 brunoerg: crACK faecde9 Tree-SHA512: ff726ed632d8d369c96d316bafebe87ff385e47b74b1d1da79409ddf296559eb991431883858057527e5df2414c01812ecbc99c21c69020228b0747f32b03121
2 parents 8cf2137 + faecde9 commit d00d50e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/test/util/setup_common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#ifndef BITCOIN_TEST_UTIL_SETUP_COMMON_H
66
#define BITCOIN_TEST_UTIL_SETUP_COMMON_H
77

8-
#include <common/args.h>
8+
#include <common/args.h> // IWYU pragma: export
99
#include <key.h>
1010
#include <node/caches.h>
1111
#include <node/context.h> // IWYU pragma: export
1212
#include <primitives/transaction.h>
1313
#include <pubkey.h>
1414
#include <stdexcept>
15-
#include <util/chaintype.h>
15+
#include <util/chaintype.h> // IWYU pragma: export
1616
#include <util/check.h>
1717
#include <util/fs.h>
1818
#include <util/string.h>

src/wallet/test/fuzz/scriptpubkeyman.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,37 @@
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 <addresstype.h>
56
#include <chainparams.h>
6-
#include <validation.h>
7+
#include <coins.h>
8+
#include <key.h>
9+
#include <primitives/transaction.h>
10+
#include <psbt.h>
11+
#include <script/descriptor.h>
12+
#include <script/interpreter.h>
13+
#include <script/script.h>
14+
#include <script/signingprovider.h>
15+
#include <sync.h>
716
#include <test/fuzz/FuzzedDataProvider.h>
817
#include <test/fuzz/fuzz.h>
918
#include <test/fuzz/util.h>
1019
#include <test/fuzz/util/descriptor.h>
1120
#include <test/util/setup_common.h>
21+
#include <util/check.h>
22+
#include <util/translation.h>
23+
#include <validation.h>
1224
#include <wallet/scriptpubkeyman.h>
13-
#include <wallet/wallet.h>
1425
#include <wallet/test/util.h>
26+
#include <wallet/types.h>
27+
#include <wallet/wallet.h>
28+
#include <wallet/walletutil.h>
29+
30+
#include <map>
31+
#include <memory>
32+
#include <optional>
33+
#include <string>
34+
#include <utility>
35+
#include <variant>
1536

1637
namespace wallet {
1738
namespace {
@@ -99,7 +120,9 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm)
99120
bool extract_dest{ExtractDestination(spk, dest)};
100121
if (extract_dest) {
101122
const std::string msg{fuzzed_data_provider.ConsumeRandomLengthString()};
102-
PKHash pk_hash{fuzzed_data_provider.ConsumeBool() ? PKHash{ConsumeUInt160(fuzzed_data_provider)} : *std::get_if<PKHash>(&dest)};
123+
PKHash pk_hash{std::get_if<PKHash>(&dest) && fuzzed_data_provider.ConsumeBool() ?
124+
*std::get_if<PKHash>(&dest) :
125+
PKHash{ConsumeUInt160(fuzzed_data_provider)}};
103126
std::string str_sig;
104127
(void)spk_manager->SignMessage(msg, pk_hash, str_sig);
105128
}

0 commit comments

Comments
 (0)