bitcoin/src/wallet
fanquake 5bb03fba04
Merge bitcoin/bitcoin#23333: wallet: fix segfault by avoiding invalid default-ctored external_spk_managers entry
6911ab95f1 wallet: fix segfault by avoiding invalid default-ctored `external_spk_managers` entry (Sebastian Falbesoner)

Pull request description:

  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):

  ```
  $ ./src/bitcoind -regtest -daemon
  $ ./src/bitcoin-cli -regtest -named createwallet_name=wallet descriptors=true blank=true
  $ cat regtest-descriptors.txt
  [
    {
      "desc": "tr([e4445899/49'/1'/0']tprv8ZgxMBicQKsPd8jCeBWsYLEoWxbVgzJDatJ7XkwQ6G3uF4FsHuaziHQ5JZAW4K515nj6kVVwPaNWZSMEcR7aFCwL4tQqTcaoprMKTTtm6Zg/1/*)#mr3llm7f",
      "timestamp": 1634652324,
      "active": true,
      "internal": true,
      "range": [
        0,
        999
      ],
      "next": 0
    }
  ]
  $ ./src/bitcoin-cli -regtest importdescriptors "$(cat regtest-descriptors.txt)"
  [
    {
      "success": true
    }
  ]
  $ ./src/bitcoin-cli -regtest getwalletinfo
  error: timeout on transient error: Could not connect to the server 127.0.0.1:18443 (error code 1 - "EOF reached")
  ```

ACKs for top commit:
  achow101:
    Code Review ACK 6911ab95f1
  lsilva01:
    Tested ACK 6911ab9  on Ubuntu 20.04.
  instagibbs:
    ACK 6911ab95f1

Tree-SHA512: 76aa96847cf2739413fb68fb902afef0b3ab9381178dd62fb0abac69f853f1f6523d73c60e610375b9a7730f275eda9162503b89f5be6e6e349a8d047b59c8dc
2021-10-22 20:35:35 +08:00
..
test refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
bdb.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
bdb.h refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
coincontrol.cpp refactor: Drop CCoinControl::SetNull 2021-04-18 21:10:47 +01:00
coincontrol.h External input fund support cleanups 2021-10-06 06:55:34 +08:00
coinselection.cpp Merge bitcoin/bitcoin#22951: consensus: move amount.h into consensus 2021-10-05 09:43:23 +02:00
coinselection.h Merge bitcoin/bitcoin#22951: consensus: move amount.h into consensus 2021-10-05 09:43:23 +02:00
context.cpp Remove g_rpc_chain global 2020-05-28 02:13:19 -04:00
context.h refactor: remove ::vpwallets and related global variables 2021-08-17 04:05:15 -04:00
crypter.cpp refactor: Replace &foo[0] with foo.data() 2021-05-04 06:55:31 +02:00
crypter.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
db.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
db.h refactor: post Optional<> removal cleanups 2021-03-17 14:56:20 +08:00
dump.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
dump.h wallettool: Add createfromdump command 2020-12-16 12:33:06 -05:00
external_signer_scriptpubkeyman.cpp Merge bitcoin/bitcoin#21365: Basic Taproot signing support for descriptor wallets 2021-06-18 09:12:44 +12:00
external_signer_scriptpubkeyman.h refactor: remove m_internal from DescriptorSPKman 2021-06-30 08:37:50 +02:00
feebumper.cpp refactor: Detach wallet transaction methods (followup for move-only) 2021-09-01 02:22:58 -05:00
feebumper.h wallet: Avoid translating RPC errors when creating txs 2020-05-01 07:39:06 -04:00
fees.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
fees.h [MOVEONLY] consensus: move amount.h into consensus 2021-09-30 07:41:57 +08:00
init.cpp Remove -rescan startup parameter 2021-09-30 12:06:27 +13:00
interfaces.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
ismine.h doc: Add developer documentation to isminetype 2021-01-19 19:04:45 +08:00
load.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
load.h refactor: remove ::vpwallets and related global variables 2021-08-17 04:05:15 -04:00
receive.cpp [MOVEONLY] consensus: move amount.h into consensus 2021-09-30 07:41:57 +08:00
receive.h [MOVEONLY] consensus: move amount.h into consensus 2021-09-30 07:41:57 +08:00
rpcdump.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
rpcwallet.cpp Merge bitcoin/bitcoin#23002: Make descriptor wallets by default 2021-10-22 13:31:10 +02:00
rpcwallet.h refactor: replace util::Ref by std::any (C++17) 2021-03-29 23:29:42 +02:00
salvage.cpp Remove -rescan startup parameter 2021-09-30 12:06:27 +13:00
salvage.h wallettool: Have RecoverDatabaseFile return errors and warnings 2020-07-26 20:22:45 -04:00
scriptpubkeyman.cpp Merge bitcoin/bitcoin#23093: Add ability to flush keypool and always flush when upgrading non-HD to HD 2021-10-14 18:05:58 +02:00
scriptpubkeyman.h refactor: Remove unused KeyIDHasher 2021-08-22 17:31:58 +02:00
spend.cpp External input fund support cleanups 2021-10-06 06:55:34 +08:00
spend.h Merge bitcoin/bitcoin#22951: consensus: move amount.h into consensus 2021-10-05 09:43:23 +02:00
sqlite.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
sqlite.h doc: fix various typos 2021-01-04 12:31:31 +08:00
transaction.cpp MOVEONLY: CWallet transaction code out of wallet.cpp/.h 2021-05-26 06:32:51 -05:00
transaction.h Merge bitcoin/bitcoin#22951: consensus: move amount.h into consensus 2021-10-05 09:43:23 +02:00
wallet.cpp wallet: fix segfault by avoiding invalid default-ctored external_spk_managers entry 2021-10-21 16:26:50 +02:00
wallet.h Merge bitcoin/bitcoin#22951: consensus: move amount.h into consensus 2021-10-05 09:43:23 +02:00
walletdb.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
walletdb.h Merge bitcoin/bitcoin#22951: consensus: move amount.h into consensus 2021-10-05 09:43:23 +02:00
wallettool.cpp Merge bitcoin/bitcoin#23002: Make descriptor wallets by default 2021-10-22 13:31:10 +02:00
wallettool.h refactor: Move all command dependend checks to ExecuteWalletToolFunc 2021-01-21 19:30:34 +01:00
walletutil.cpp refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
walletutil.h wallet: Upgrade existing descriptor caches 2021-06-24 13:49:22 -04:00