Skip to content

Commit 3ef77a0

Browse files
committed
Reject duplicate wallet filenames
1 parent 0b11a07 commit 3ef77a0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,24 @@ bool CWallet::Verify()
468468

469469
uiInterface.InitMessage(_("Verifying wallet(s)..."));
470470

471+
// Keep track of each wallet absolute path to detect duplicates.
472+
std::set<fs::path> wallet_paths;
473+
471474
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
472475
if (boost::filesystem::path(walletFile).filename() != walletFile) {
473476
return InitError(_("-wallet parameter must only specify a filename (not a path)"));
474-
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
477+
}
478+
479+
if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
475480
return InitError(_("Invalid characters in -wallet filename"));
476481
}
477482

483+
fs::path wallet_path = fs::absolute(walletFile, GetDataDir());
484+
485+
if (!wallet_paths.insert(wallet_path).second) {
486+
return InitError(_("Duplicate -wallet filename"));
487+
}
488+
478489
std::string strError;
479490
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError)) {
480491
return InitError(strError);

test/functional/multiwallet.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ def __init__(self):
1818
self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3']]
1919

2020
def run_test(self):
21+
self.stop_node(0)
22+
23+
# should not initialize if there are duplicate wallets
24+
self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w1', '-wallet=w1'], 'Duplicate -wallet filename')
25+
26+
self.nodes[0] = self.start_node(0, self.options.tmpdir, self.extra_args[0])
27+
2128
w1 = self.nodes[0] / "wallet/w1"
2229
w1.generate(1)
2330

0 commit comments

Comments
 (0)