Skip to content

Commit a1f4e2a

Browse files
committed
Reject duplicate wallet filenames
>>> backports bitcoin/bitcoin@3ef77a0
1 parent ee52c2e commit a1f4e2a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2121,13 +2121,23 @@ bool CWallet::Verify()
21212121

21222122
uiInterface.InitMessage(_("Verifying wallet(s)..."));
21232123

2124+
// Keep track of each wallet absolute path to detect duplicates.
2125+
std::set<fs::path> wallet_paths;
2126+
21242127
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
21252128
if (fs::path(walletFile).filename() != walletFile) {
21262129
return UIError(strprintf(_("%s parameter must only specify a filename (not a path)"), "-wallet"));
2127-
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
2130+
}
2131+
if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
21282132
return UIError(strprintf(_("Invalid characters in %s filename"), "-wallet"));
21292133
}
21302134

2135+
fs::path wallet_path = fs::absolute(walletFile, GetDataDir());
2136+
2137+
if (!wallet_paths.insert(wallet_path).second) {
2138+
return UIError(strprintf(_("Duplicate %s filename"), "-wallet"));
2139+
}
2140+
21312141
std::string strError;
21322142
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError)) {
21332143
return UIError(strError);

test/functional/wallet_multiwallet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def run_test(self):
3737
#self.assert_start_raises_init_error(0, ['-walletdir=debug.log'], 'Error: Specified -walletdir "debug.log" is not a directory', cwd=data_dir())
3838

3939
# should not initialize if there are duplicate wallets
40-
# !TODO: backport bitcoin#10885
41-
#self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.')
40+
self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Duplicate -wallet filename')
4241

4342
# should not initialize if wallet file is a directory
4443
# !TODO: backport bitcoin#11476 + bitcoin#11970

0 commit comments

Comments
 (0)