Skip to content

Commit

Permalink
Reject duplicate wallet filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Jun 2, 2021
1 parent ee52c2e commit a1f4e2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,13 +2121,23 @@ bool CWallet::Verify()

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

// Keep track of each wallet absolute path to detect duplicates.
std::set<fs::path> wallet_paths;

for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
if (fs::path(walletFile).filename() != walletFile) {
return UIError(strprintf(_("%s parameter must only specify a filename (not a path)"), "-wallet"));
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
}
if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
return UIError(strprintf(_("Invalid characters in %s filename"), "-wallet"));
}

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

if (!wallet_paths.insert(wallet_path).second) {
return UIError(strprintf(_("Duplicate %s filename"), "-wallet"));
}

std::string strError;
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError)) {
return UIError(strError);
Expand Down
3 changes: 1 addition & 2 deletions test/functional/wallet_multiwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def run_test(self):
#self.assert_start_raises_init_error(0, ['-walletdir=debug.log'], 'Error: Specified -walletdir "debug.log" is not a directory', cwd=data_dir())

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

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

0 comments on commit a1f4e2a

Please sign in to comment.