From 3ef77a0c1288df524fdf0c90ca70c986f473b787 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20Barbosa?= Date: Thu, 27 Jul 2017 00:56:30 +0100 Subject: [PATCH] Reject duplicate wallet filenames --- src/wallet/wallet.cpp | 13 ++++++++++++- test/functional/multiwallet.py | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3e9c531f0..ccf5353eb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -468,13 +468,24 @@ 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 (boost::filesystem::path(walletFile).filename() != walletFile) { return InitError(_("-wallet parameter must only specify a filename (not a path)")); - } else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) { + } + + if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) { return InitError(_("Invalid characters in -wallet filename")); } + fs::path wallet_path = fs::absolute(walletFile, GetDataDir()); + + if (!wallet_paths.insert(wallet_path).second) { + return InitError(_("Duplicate -wallet filename")); + } + std::string strError; if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError)) { return InitError(strError); diff --git a/test/functional/multiwallet.py b/test/functional/multiwallet.py index 173f06cf5..5844d9913 100755 --- a/test/functional/multiwallet.py +++ b/test/functional/multiwallet.py @@ -18,6 +18,13 @@ class MultiWalletTest(BitcoinTestFramework): self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3']] def run_test(self): + self.stop_node(0) + + # should not initialize if there are duplicate wallets + self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w1', '-wallet=w1'], 'Duplicate -wallet filename') + + self.nodes[0] = self.start_node(0, self.options.tmpdir, self.extra_args[0]) + w1 = self.nodes[0] / "wallet/w1" w1.generate(1) -- 2.11.4.GIT