From a1f4e2a267e83354c5210bc04dc962b22c8b1bbd Mon Sep 17 00:00:00 2001 From: random-zebra Date: Wed, 28 Apr 2021 22:38:18 +0200 Subject: [PATCH] Reject duplicate wallet filenames >>> backports bitcoin@3ef77a0c1288df524fdf0c90ca70c986f473b787 --- src/wallet/wallet.cpp | 12 +++++++++++- test/functional/wallet_multiwallet.py | 3 +-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c6da2e890c1ad..57273ebbfeda5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2121,13 +2121,23 @@ bool CWallet::Verify() uiInterface.InitMessage(_("Verifying wallet(s)...")); + // Keep track of each wallet absolute path to detect duplicates. + std::set 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); diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 317789f5cc1bf..75c751fe64396 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -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