Skip to content

Commit

Permalink
Reject invalid wallet files
Browse files Browse the repository at this point in the history
  • Loading branch information
promag authored and random-zebra committed Jun 2, 2021
1 parent a1f4e2a commit 900bbfa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,10 @@ bool CWallet::Verify()

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

if (fs::exists(wallet_path) && (!fs::is_regular_file(wallet_path) || fs::is_symlink(wallet_path))) {
return UIError(_("Invalid -wallet file"));
}

if (!wallet_paths.insert(wallet_path).second) {
return UIError(strprintf(_("Duplicate %s filename"), "-wallet"));
}
Expand Down
10 changes: 7 additions & 3 deletions test/functional/wallet_multiwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ def run_test(self):

# should not initialize if wallet file is a directory
# !TODO: backport bitcoin#11476 + bitcoin#11970
# os.mkdir(wallet_dir('w11'))
# self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')
os.mkdir(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w11'))
self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Invalid -wallet file')
#os.mkdir(wallet_dir('w11'))
#self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')

# should not initialize if one wallet is a copy of another
# shutil.copyfile(wallet_dir('w2'), wallet_dir('w22'))
# self.assert_start_raises_init_error(0, ['-wallet=w2', '-wallet=w22'], 'duplicates fileid')

# should not initialize if wallet file is a symlink
# !TODO: backport bitcoin#10885
os.symlink(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w1'),
os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w12'))
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Invalid -wallet file')
# os.symlink(wallet_dir('w1'), wallet_dir('w12'))
# self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')

Expand Down

0 comments on commit 900bbfa

Please sign in to comment.