wallet: Do not iterate a directory if having an error while accessing it #21907

pull hebasto wants to merge 1 commits into bitcoin:master from hebasto:210510-win changing 1 files +6 −1
  1. hebasto commented at 6:56 PM on May 10, 2021: member

    On Windows when ListDatabases tries to iterate any system folder, e.g., "System Volume Information", it falls into an infinite loop.

    This PR fixes this bug. Now the debug.log contains:

    2021-05-12T09:07:53Z ListDatabases: Access is denied D:/System Volume Information -- skipping.
    

    An easy way to reproduce the bug and test this PR is to pass the -walletdir=D:\ command-line option, and run the listwalletdir RPC, or File -> Open Wallet in the GUI menu.

    Fixes #20081. Fixes #21136. Fixes #21904.

    Also https://bitcoin.stackexchange.com/questions/99243/listwalletdir-access-is-denied-d-system-volume-information

  2. hebasto added the label Bug on May 10, 2021
  3. hebasto added the label Wallet on May 10, 2021
  4. hebasto added the label Windows on May 10, 2021
  5. hebasto force-pushed on May 10, 2021
  6. in src/wallet/db.cpp:27 in bd13ec6d83 outdated
      22 | @@ -19,6 +23,12 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
      23 |      for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
      24 |          if (ec) {
      25 |              LogPrintf("%s: %s %s\n", __func__, ec.message(), it->path().string());
      26 | +#ifdef WIN32
      27 | +            if (ec.value() == boost::system::windows_error::access_denied) {
    


    laanwj commented at 11:20 AM on May 11, 2021:

    Is this specific to windows? Or could this happen with directory "access denied" errors on other OSes as well?


    hebasto commented at 11:53 AM on May 11, 2021:

    Is this specific to windows?

    The error code is specific to windows.

    Or could this happen with directory "access denied" errors on other OSes as well?

    Yes, it could. But on other OSes the reason of "access denied" errors is a bad setup that a user can/should fix. On windows this situation seems common and not always fixable by a user.


    promag commented at 8:30 AM on May 12, 2021:

    Maybe it should avoid recursion regardless of the error and platform? Is there any case where this approach is not desirable?


    hebasto commented at 8:44 AM on May 12, 2021:

    Maybe it should avoid recursion regardless of the error and platform? Is there any case where this approach is not desirable?

    To be sure I understand you correctly, you are suggesting do not iterate a directory if we have any error while accessing it, right?


    promag commented at 8:46 AM on May 12, 2021:

    Yes, that was my suggestion. Is there any downside of that approach?


    hebasto commented at 9:20 AM on May 12, 2021:
  7. sipsorcery commented at 12:24 PM on May 11, 2021: member

    Started with:

    bitcoin-qt.exe -walletdir=c:\

    Is this error message expected? The app continues as normal once OK is clicked.

    bitcoin-qt_walletdir

    On master the message is a warning:

    bitcoin_qt_warning

  8. hebasto commented at 4:09 PM on May 11, 2021: member

    @sipsorcery

    Started with:

    bitcoin-qt.exe -walletdir=c:\

    Is this error message expected? The app continues as normal once OK is clicked.

    I cannot reproduce neither error message with this PR nor warning message on master. Could you share other relevant non-private options from the bitcoin.conf, or the debug.log from the beginning (where options are logged)?

    In any case, -walletdir=c:\ on windows is a bad practice :)

  9. sipsorcery commented at 4:25 PM on May 11, 2021: member

    I cannot reproduce neither error message with this PR nor warning message on master. Could you share other relevant non-private options from the bitcoin.conf, or the debug.log from the beginning (where options are logged)?

    I checked my bitcoin.conf at the time and made sure it was empty. I've attempted to repeat the steps with a fresh configuration and have managed to delete my whole bitcoin directory. Using the same command line I now don't get the error or warning prompt with either bitcoin-qt version. I'll play around a bit more to try and find what generates the previous messages.

    In any case, -walletdir=c:\ on windows is a bad practice :)

    Sure I was only attempting to test the fix in this PR by getting the wallet logic to scan the root drive. I don't have a D:\ drive.

    When using bitcoin-qt from master and bitcoin-qt.exe -regtest -walletdir=c:\ I don't get an error about attempting to access c:\System Volume Information. I'll retry with the symbolic link mentioned in #20081 although to be honest symbolic linking a root drive from within the Bitcoin app data directory seems like asking for trouble.

  10. hebasto commented at 4:49 PM on May 11, 2021: member

    In any case, -walletdir=c:\ on windows is a bad practice :)

    Sure I was only attempting to test the fix in this PR by getting the wallet logic to scan the root drive. I don't have a D:\ drive.

    With this PR it is possible to scan C:\ without hanging the client, but it takes really long time :)

  11. hebasto commented at 4:50 PM on May 11, 2021: member

    I don't have a D:\ drive.

    A USB flash-drive could work, no?

  12. unknown commented at 8:30 AM on May 12, 2021: none
    1. bitcoin-qt.exe -walletdir=E:\ Not Responding when I try to open wallets

    image

    1. bitcoind.exe -walletdir=E:\

    Not sure why its using forward slash which is used in Linux

    2021-05-12T08:05:49Z Using wallet directory E:/
    2021-05-12T08:05:49Z init message: Verifying wallet(s)...
    2021-05-12T08:05:49Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
    2021-05-12T08:05:49Z Using wallet E:/wallet.dat
    

    bitcoin-cli.exe listwalletdir returns nothing and cmd prompt running bitcoind starts printing error continuously until I close it.

    image

    Will compile the branch for this PR in some time and two more things that I noticed:

    1. "E:" works when used with datadir but gives error for walletdir
    2. https://bitcoin.stackexchange.com/questions/103295/unable-to-use-blocks-and-chainstate-from-external-drive
  13. promag commented at 8:31 AM on May 12, 2021: member

    Concept ACK.

  14. wallet: Do not iterate a directory if having an error while accessing it
    This change prevents infinite looping for, for example, system folders
    on Windows.
    29c9e2c2d2
  15. hebasto force-pushed on May 12, 2021
  16. hebasto commented at 9:16 AM on May 12, 2021: member

    Updated bd13ec6d834d4c5f20a5ff9ab41e2e9e86f32d93 -> 29c9e2c2d2015ade47ed4497926363dea3f9c59b (pr21907.01 -> pr21907.02, diff):

    UPDATE: After moving to std::filesystem we can drop this change in favor of skip_permission_denied.

  17. hebasto renamed this:
    wallet: Do not iterate system folders on Windows
    wallet: Do not iterate a directory if having an error while accessing it
    on May 12, 2021
  18. hebasto removed the label Windows on May 12, 2021
  19. ghost commented at 2:10 PM on May 12, 2021: none

    Compiled branch for this PR

    1. bitcoin-qt.exe -walletdir=E:\ I am able to see some names in File->Open Wallet
    2. bitcoind.exe -walletdir=E:\ and bitcoin-cli.exe listwalletdir works fine
    2021-05-12T13:35:53Z ListDatabases: Access is denied E:/System Volume Information -- skipping.
    

    I see few names returned by listwalletdir

    ACK https://github.com/bitcoin/bitcoin/pull/21907/commits/29c9e2c2d2015ade47ed4497926363dea3f9c59b

    Found some issues with weird wallet names and path but its not related to this PR IMO: #21510 (comment)

  20. promag commented at 2:35 PM on May 12, 2021: member

    Code review ACK 29c9e2c2d2015ade47ed4497926363dea3f9c59b.

  21. meshcollider commented at 8:54 AM on May 13, 2021: contributor

    Code review ACK 29c9e2c2d2015ade47ed4497926363dea3f9c59b

  22. meshcollider merged this on May 13, 2021
  23. meshcollider closed this on May 13, 2021

  24. hebasto deleted the branch on May 13, 2021
  25. sidhujag referenced this in commit da5c7248f0 on May 13, 2021
  26. meshcollider referenced this in commit 69577a27ab on Jun 9, 2021
  27. sidhujag referenced this in commit a150948159 on Jun 9, 2021
  28. luke-jr referenced this in commit 7b0b201d10 on Jun 15, 2021
  29. fanquake commented at 1:36 AM on July 1, 2021: member

    Backported to 0.21 in #22255.

  30. MarcoFalke referenced this in commit 4c29b63cfb on Jul 1, 2021
  31. gwillen referenced this in commit d9d4910a7d on Jun 1, 2022
  32. PastaPastaPasta referenced this in commit cd47c6bd48 on Apr 10, 2023
  33. PastaPastaPasta referenced this in commit dc1f37e51a on Apr 15, 2023
  34. PastaPastaPasta referenced this in commit 436245d732 on Apr 15, 2023
  35. PastaPastaPasta referenced this in commit 165ca7a39b on Apr 15, 2023
  36. PastaPastaPasta referenced this in commit e2203f9470 on Apr 16, 2023
  37. PastaPastaPasta referenced this in commit 0cd4553927 on Apr 16, 2023
  38. UdjinM6 referenced this in commit 3aab3efaa5 on Apr 16, 2023
  39. DrahtBot locked this on Jun 17, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me