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