Skip to content

Commit a6da027

Browse files
committed
Reject invalid wallet files
1 parent 3ef77a0 commit a6da027

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ bool CWallet::Verify()
482482

483483
fs::path wallet_path = fs::absolute(walletFile, GetDataDir());
484484

485+
if (fs::exists(wallet_path) && (!fs::is_regular_file(wallet_path) || fs::is_symlink(wallet_path))) {
486+
return InitError(_("Invalid -wallet file"));
487+
}
488+
485489
if (!wallet_paths.insert(wallet_path).second) {
486490
return InitError(_("Duplicate -wallet filename"));
487491
}

test/functional/multiwallet.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
77
Verify that a bitcoind node can load multiple wallet files
88
"""
9+
import os
10+
911
from test_framework.test_framework import BitcoinTestFramework
1012
from test_framework.util import assert_equal, assert_raises_jsonrpc
1113

@@ -23,6 +25,14 @@ def run_test(self):
2325
# should not initialize if there are duplicate wallets
2426
self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w1', '-wallet=w1'], 'Duplicate -wallet filename')
2527

28+
# should not initialize if wallet file is a directory
29+
os.mkdir(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w11'))
30+
self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w11'], 'Invalid -wallet file')
31+
32+
# should not initialize if wallet file is a symlink
33+
os.symlink(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w1'), os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w12'))
34+
self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w12'], 'Invalid -wallet file')
35+
2636
self.nodes[0] = self.start_node(0, self.options.tmpdir, self.extra_args[0])
2737

2838
w1 = self.nodes[0] / "wallet/w1"

0 commit comments

Comments
 (0)