File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4657,9 +4657,19 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
46574657 return util::Error{_ (" Error: This wallet is already a descriptor wallet" )};
46584658 }
46594659
4660- // Make a backup of the DB
4660+ // Make a backup of the DB in the wallet's directory with a unique filename
4661+ // based on the wallet name and current timestamp. The backup filename uses
4662+ // the basename of the wallet path (or "wallet" if the name is blank) so that
4663+ // path-style wallet names cannot escape the wallet directory.
4664+ // TODO: backport bitcoin/bitcoin#32273 to also move the backup into the
4665+ // top-level walletdir and unify with upstream.
46614666 fs::path this_wallet_dir = fs::absolute (fs::PathFromString (local_wallet->GetDatabase ().Filename ())).parent_path ();
4662- fs::path backup_filename = fs::PathFromString (strprintf (" %s-%d.legacy.bak" , wallet_name.empty () ? " wallet" : wallet_name, GetTime ()));
4667+ const std::string backup_prefix = wallet_name.empty () ? " wallet" : [&] {
4668+ // fs::weakly_canonical resolves relative specifiers and removes trailing slashes.
4669+ const auto legacy_wallet_path = fs::weakly_canonical (GetWalletDir () / fs::PathFromString (wallet_name));
4670+ return fs::PathToString (legacy_wallet_path.filename ());
4671+ }();
4672+ fs::path backup_filename = fs::PathFromString (strprintf (" %s-%d.legacy.bak" , backup_prefix, GetTime ()));
46634673 fs::path backup_path = this_wallet_dir / backup_filename;
46644674 if (!local_wallet->BackupWallet (fs::PathToString (backup_path))) {
46654675 return util::Error{_ (" Error: Unable to make a backup of your wallet" )};
You can’t perform that action at this time.
0 commit comments