Fixes #23321 (bug reported by Josef Vondrlik (josef-v)).
In the method CWallet::LoadActiveScriptPubKeyMan
, the map external_spk_managers
(or internal_spk_managers
, if parameter internal
is false) is accessed via std::map::operator[], which means that a default-ctored entry is created with a null-pointer as value, if the key doesn’t exist. As soon as this value is dereferenced, a segmentation fault occurs, e.g. in CWallet::KeypoolCountExternalKeys
.
The bevaviour can be reproduced by the following steps (starting with empty regtest datadir):
0$ ./src/bitcoind -regtest -daemon
1$ ./src/bitcoin-cli -regtest -named createwallet_name=wallet descriptors=true blank=true
2$ cat regtest-descriptors.txt
3[
4 {
5 "desc": "tr([e4445899/49'/1'/0']tprv8ZgxMBicQKsPd8jCeBWsYLEoWxbVgzJDatJ7XkwQ6G3uF4FsHuaziHQ5JZAW4K515nj6kVVwPaNWZSMEcR7aFCwL4tQqTcaoprMKTTtm6Zg/1/*)#mr3llm7f",
6 "timestamp": 1634652324,
7 "active": true,
8 "internal": true,
9 "range": [
10 0,
11 999
12 ],
13 "next": 0
14 }
15]
16$ ./src/bitcoin-cli -regtest importdescriptors "$(cat regtest-descriptors.txt)"
17[
18 {
19 "success": true
20 }
21]
22$ ./src/bitcoin-cli -regtest getwalletinfo
23error: timeout on transient error: Could not connect to the server 127.0.0.1:18443 (error code 1 - "EOF reached")