Merge bitcoin/bitcoin#36341: wallet: return error from bitcoin-wallet create
What changed, and why it matters
This is a small reliability fix for the bitcoin-wallet command-line tool. Previously, when you tried to create a wallet that already existed, the tool printed an error message but still exited with status 0, which is the code normally used for success. Scripts and automated tools checking the exit code would therefore incorrectly think the command succeeded. The patch makes the tool return a non-zero exit code on failure, matching the behavior of other wallet tool commands. There is no security vulnerability allowing theft, remote attack, or code execution.
No urgent action required. This is a minor correctness/reliability improvement. Users relying on bitcoin-wallet create in scripts should upgrade to a release containing this fix to ensure proper error detection, but there is no immediate security risk.
Security signals we found
Incorrect exit status on failure (success/failure confusion)
Command-line tool behavior inconsistent with other commands
Potential for scripts to misinterpret failed wallet creation as successful
Evidence from the diff
In src/wallet/wallettool.cpp, the ‘create’ branch of ExecuteWalletToolFunc previously only acted when MakeWallet succeeded and then fell through to return true. If MakeWallet failed (e.g., because the wallet database already existed), the function still returned true, causing bitcoin-wallet to exit with status 0. The patch changes the branch to return false when MakeWallet fails, consistent with the ‘info’, ‘dump’, and ‘createfromdump’ commands. A functional test is added to verify that running ‘create’ on an existing wallet produces a non-zero exit code and the expected ‘Database already exists.’ error.
Changed components
src/wallet/wallettool.cppbitcoin-wallet CLI toolwallet creation commandInspect captured patch +6 / −4
### src/wallet/wallettool.cpp
@@ -124,10 +124,9 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
options.require_format = DatabaseFormat::SQLITE;
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
- if (wallet_instance) {
- WalletShowInfo(wallet_instance.get());
- wallet_instance->Close();
- }
+ if (!wallet_instance) return false;
+ WalletShowInfo(wallet_instance.get());
+ wallet_instance->Close();
} else if (command == "info") {
DatabaseOptions options;
ReadDatabaseArgs(args, options);
### test/functional/tool_wallet.py
@@ -221,6 +221,9 @@ def test_tool_wallet_create_on_existing_wallet(self):
assert_equal(shasum_before, shasum_after)
self.log.debug('Wallet file shasum unchanged\n')
+ self.log.info('Calling wallet tool create on a wallet that already exists, testing error')
+ self.assert_raises_tool_error('Database already exists.', '-wallet=foo', 'create')
+
def test_getwalletinfo_on_different_wallet(self):
self.log.info('Starting node with arg -wallet=foo')
self.start_node(0, ['-nowallet', '-wallet=foo'])Why this scored 24/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.