Skip to content

Commit

Permalink
Reject duplicate wallet filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
promag committed Jul 28, 2017
1 parent 0b11a07 commit 3ef77a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/wallet/wallet.cpp
Expand Up @@ -468,13 +468,24 @@ 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 (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);
Expand Down
7 changes: 7 additions & 0 deletions test/functional/multiwallet.py
Expand Up @@ -18,6 +18,13 @@ def __init__(self):
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)

Expand Down

0 comments on commit 3ef77a0

Please sign in to comment.