Skip to content

Commit fa73460

Browse files
author
MarcoFalke
committed
wallet: Fix segmentation fault in CreateWalletFromFile
1 parent fab3c34 commit fa73460

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4243,7 +4243,7 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b
42434243

42444244
std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, uint64_t wallet_creation_flags)
42454245
{
4246-
const std::string& walletFile = WalletDataFilePath(location.GetPath()).string();
4246+
const std::string walletFile = WalletDataFilePath(location.GetPath()).string();
42474247

42484248
// needed to restore wallet transaction meta data after -zapwallettxes
42494249
std::vector<CWalletTx> vWtx;

test/functional/data/wallets/high_minversion/.walletlock

Whitespace-only changes.

test/functional/data/wallets/high_minversion/db.log

Whitespace-only changes.
Binary file not shown.

test/functional/wallet_multiwallet.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
assert_raises_rpc_error,
1818
)
1919

20+
FEATURE_LATEST = 169900
21+
2022

2123
class MultiWalletTest(BitcoinTestFramework):
2224
def set_test_params(self):
@@ -27,6 +29,13 @@ def set_test_params(self):
2729
def skip_test_if_missing_module(self):
2830
self.skip_if_no_wallet()
2931

32+
def add_options(self, parser):
33+
parser.add_argument(
34+
'--data_wallets_dir',
35+
default=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/wallets/'),
36+
help='Test data with wallet directories (default: %(default)s)',
37+
)
38+
3039
def run_test(self):
3140
node = self.nodes[0]
3241

@@ -323,6 +332,22 @@ def wallet_file(name):
323332
self.nodes[0].unloadwallet(wallet)
324333
self.nodes[1].loadwallet(wallet)
325334

335+
# Fail to load if wallet is downgraded
336+
shutil.copytree(os.path.join(self.options.data_wallets_dir, 'high_minversion'), wallet_dir('high_minversion'))
337+
self.restart_node(0, extra_args=['-upgradewallet={}'.format(FEATURE_LATEST)])
338+
assert {'name': 'high_minversion'} in self.nodes[0].listwalletdir()['wallets']
339+
self.log.info("Fail -upgradewallet that results in downgrade")
340+
assert_raises_rpc_error(
341+
-4,
342+
"Wallet loading failed.",
343+
lambda: self.nodes[0].loadwallet(filename='high_minversion'),
344+
)
345+
self.stop_node(
346+
i=0,
347+
expected_stderr='Error: Error loading {}: Wallet requires newer version of Bitcoin Core'.format(
348+
wallet_dir('high_minversion', 'wallet.dat')),
349+
)
350+
326351

327352
if __name__ == '__main__':
328353
MultiWalletTest().main()

0 commit comments

Comments
 (0)