bitcoinknots / bitcoin

Bitcoin Knots enhanced Bitcoin node/wallet software
MIT License
199 stars 60 forks source link

fix bitcoin issue #19928 also for knots #28

Closed Saibato closed 3 years ago

Saibato commented 3 years ago

This patch ̶s̶h̶o̶u̶l̶d̶ fix the issue reported in https://github.com/bitcoin/bitcoin/issues/19928

diff --git a/src/wallet/walletutil.cpp b/src/wallet/walletutil.cpp
index 39520267c..a7f7eb819 100644
--- a/src/wallet/walletutil.cpp
+++ b/src/wallet/walletutil.cpp
@@ -63,7 +63,9 @@ std::vector<fs::path> ListWalletDir()
     const fs::path data_dir = GetDataDir();
     const fs::path blocks_dir = GetBlocksDir();

-    const size_t offset = wallet_dir.string().size() + 1;
+    // account for possible trailing backslash, since we might have only boost 1.47 we could not use fs::relative
+    const size_t offset = (wallet_dir.string().back() != '/') ? wallet_dir.string().size() + 1 : wallet_dir.parent_path().string().size() + 1;
+
     std::vector<fs::path> paths;
     boost::system::error_code ec;
     boost::system::error_code eci;

edit@saibato ̶S̶t̶i̶l̶l̶ ̶d̶r̶a̶f̶t̶:̶ ̶ ̶W̶i̶l̶l̶ ̶d̶o̶ ̶o̶n̶l̶y̶ ̶p̶a̶r̶t̶l̶y̶ ̶t̶h̶e̶ ̶j̶o̶b̶,̶ ̶h̶m̶m̶.̶.̶.̶

If a user would add a trailing '/' or more e.g. '////' to the -datadir path, listwalletdir would strip one char of the wallename with every open. This will happen if there is no wallets subdir e.g an older node or the wallets dir would have been renamed

Saibato commented 3 years ago

fixed in core by https://github.com/bitcoin/bitcoin/pull/20080 closing this now. ;-)