Skip to content

Commit ea65182

Browse files
committed
[wallet] loadwallet shouldn't create new wallets.
A bug in the initial implementation of loadwallet meant that if the arguement was a directory that didn't contain a wallet.dat file, a new wallet would be created in that directory. Fix that so that if a directory is passed in, it must contain a wallet.dat file. Bug reported by promag (João Barbosa).
1 parent d96bdd7 commit ea65182

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,12 @@ static UniValue loadwallet(const JSONRPCRequest& request)
30923092
fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir());
30933093
if (fs::symlink_status(wallet_path).type() == fs::file_not_found) {
30943094
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Wallet " + wallet_file + " not found.");
3095+
} else if (fs::is_directory(wallet_path)) {
3096+
// The given filename is a directory. Check that there's a wallet.dat file.
3097+
fs::path wallet_dat_file = wallet_path / "wallet.dat";
3098+
if (fs::symlink_status(wallet_dat_file).type() == fs::file_not_found) {
3099+
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Directory " + wallet_file + " does not contain a wallet.dat file.");
3100+
}
30953101
}
30963102

30973103
std::string warning;

test/functional/wallet_multiwallet.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ def run_test(self):
211211
# Fail to load if wallet file is a symlink
212212
assert_raises_rpc_error(-4, "Wallet file verification failed: Invalid -wallet path 'w8_symlink'", self.nodes[0].loadwallet, 'w8_symlink')
213213

214+
# Fail to load if a directory is specified that doesn't contain a wallet
215+
os.mkdir(wallet_dir('empty_wallet_dir'))
216+
assert_raises_rpc_error(-18, "Directory empty_wallet_dir does not contain a wallet.dat file", self.nodes[0].loadwallet, 'empty_wallet_dir')
217+
214218
self.log.info("Test dynamic wallet creation.")
215219

216220
# Fail to create a wallet if it already exists.

0 commit comments

Comments
 (0)