Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented May 10, 2021

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

@@ -19,6 +23,12 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
if (ec) {
LogPrintf("%s: %s %s\n", __func__, ec.message(), it->path().string());
#ifdef WIN32
if (ec.value() == boost::system::windows_error::access_denied) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sipsorcery
Copy link
Contributor

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

@hebasto
Copy link
Member Author

hebasto commented May 11, 2021

@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 :)

@sipsorcery
Copy link
Contributor

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.

@hebasto
Copy link
Member Author

hebasto commented May 11, 2021

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 :)

@hebasto
Copy link
Member Author

hebasto commented May 11, 2021

I don't have a D:\ drive.

A USB flash-drive could work, no?

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

@@ -19,6 +23,12 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
if (ec) {
LogPrintf("%s: %s %s\n", __func__, ec.message(), it->path().string());
#ifdef WIN32
if (ec.value() == boost::system::windows_error::access_denied) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This change prevents infinite looping for, for example, system folders
on Windows.
@hebasto
Copy link
Member Author

hebasto commented May 12, 2021

Updated bd13ec6 -> 29c9e2c (pr21907.01 -> pr21907.02, diff):

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

@hebasto hebasto changed the title wallet: Do not iterate system folders on Windows wallet: Do not iterate a directory if having an error while accessing it May 12, 2021
@hebasto hebasto removed the Windows label May 12, 2021
@ghost ghost mentioned this pull request May 12, 2021
@ghost
Copy link

ghost commented May 12, 2021

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 29c9e2c

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

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 29c9e2c.

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 29c9e2c

@meshcollider meshcollider merged commit a31a1ce into bitcoin:master May 13, 2021
@hebasto hebasto deleted the 210510-win branch May 13, 2021 09:26
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 13, 2021
…error while accessing it

29c9e2c wallet: Do not iterate a directory if having an error while accessing it (Hennadii Stepanov)

Pull request description:

  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 bitcoin#20081.
  Fixes bitcoin#21136.
  Fixes bitcoin#21904.

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

ACKs for top commit:
  prayank23:
    ACK bitcoin@29c9e2c
  promag:
    Code review ACK 29c9e2c.
  meshcollider:
    Code review ACK 29c9e2c

Tree-SHA512: b851c88e6d09626f4cb81acc2fa59a563b2aee64582963285715bf785c64b872e8bf738aa6b27bdbaf4c3e5c8565c2dc2c802135f9aa1f48b4b913435bc5d793
meshcollider added a commit to bitcoin-core/gui that referenced this pull request Jun 9, 2021
…oot directory

d44a261 Fix issues when `walletdir` is root directory (unknown)

Pull request description:

  + Remove one character less from wallet path

  + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin/bitcoin#21907 helped me resolve the issue.

  **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed

  **Solution**: `if` statement to check `walletdir` is a root directory

  Fixes: bitcoin/bitcoin#21510 bitcoin/bitcoin#21501
  Related PR: bitcoin/bitcoin#20080

  Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`:

  Before this PR:

  ```

  {
    "wallets": [
      {
        "name": "1"
      },
      {
        "name": "2"
      }
    ]
  }

  ```

  After this PR:
  ```
    "wallets": [
      {
        "name": "w1"
      },
      {
        "name": "w2"
      }
    ]
  }

  ```

ACKs for top commit:
  ryanofsky:
    Code review ACK d44a261
  meshcollider:
    utACK d44a261

Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 9, 2021
…ctory

d44a261 Fix issues when `walletdir` is root directory (unknown)

Pull request description:

  + Remove one character less from wallet path

  + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin#21907 helped me resolve the issue.

  **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed

  **Solution**: `if` statement to check `walletdir` is a root directory

  Fixes: bitcoin#21510 bitcoin#21501
  Related PR: bitcoin#20080

  Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`:

  Before this PR:

  ```

  {
    "wallets": [
      {
        "name": "1"
      },
      {
        "name": "2"
      }
    ]
  }

  ```

  After this PR:
  ```
    "wallets": [
      {
        "name": "w1"
      },
      {
        "name": "w2"
      }
    ]
  }

  ```

ACKs for top commit:
  ryanofsky:
    Code review ACK d44a261
  meshcollider:
    utACK d44a261

Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jun 15, 2021
This change prevents infinite looping for, for example, system folders
on Windows.

Github-Pull: bitcoin#21907
Rebased-From: 29c9e2c
@fanquake
Copy link
Member

fanquake commented Jul 1, 2021

Backported to 0.21 in #22255.

maflcko pushed a commit that referenced this pull request Jul 1, 2021
…error while accessing it

7b0b201 wallet: Do not iterate a directory if having an error while accessing it (Hennadii Stepanov)

Pull request description:

  This change prevents infinite looping for, for example, system folders
  on Windows.

  Github-Pull: #21907
  Rebased-From: 29c9e2c

  Note: Trivial backport, but in a differently-named function in another file

ACKs for top commit:
  hebasto:
    ACK 7b0b201, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: d41ab267250e8bfd9289cacf1fd804cc1a3bb20fc479dc9da5a69ebf26530b552b11b2ee6b11e17a1c146ca792ee65bd64eeb2269fa5e73a70361da8a2a09925
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 10, 2023
…error while accessing it

29c9e2c wallet: Do not iterate a directory if having an error while accessing it (Hennadii Stepanov)

Pull request description:

  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 bitcoin#20081.
  Fixes bitcoin#21136.
  Fixes bitcoin#21904.

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

ACKs for top commit:
  prayank23:
    ACK bitcoin@29c9e2c
  promag:
    Code review ACK 29c9e2c.
  meshcollider:
    Code review ACK 29c9e2c

Tree-SHA512: b851c88e6d09626f4cb81acc2fa59a563b2aee64582963285715bf785c64b872e8bf738aa6b27bdbaf4c3e5c8565c2dc2c802135f9aa1f48b4b913435bc5d793
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2023
…error while accessing it

29c9e2c wallet: Do not iterate a directory if having an error while accessing it (Hennadii Stepanov)

Pull request description:

  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 bitcoin#20081.
  Fixes bitcoin#21136.
  Fixes bitcoin#21904.

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

ACKs for top commit:
  prayank23:
    ACK bitcoin@29c9e2c
  promag:
    Code review ACK 29c9e2c.
  meshcollider:
    Code review ACK 29c9e2c

Tree-SHA512: b851c88e6d09626f4cb81acc2fa59a563b2aee64582963285715bf785c64b872e8bf738aa6b27bdbaf4c3e5c8565c2dc2c802135f9aa1f48b4b913435bc5d793
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2023
…ctory

d44a261 Fix issues when `walletdir` is root directory (unknown)

Pull request description:

  + Remove one character less from wallet path

  + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin#21907 helped me resolve the issue.

  **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed

  **Solution**: `if` statement to check `walletdir` is a root directory

  Fixes: bitcoin#21510 bitcoin#21501
  Related PR: bitcoin#20080

  Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`:

  Before this PR:

  ```

  {
    "wallets": [
      {
        "name": "1"
      },
      {
        "name": "2"
      }
    ]
  }

  ```

  After this PR:
  ```
    "wallets": [
      {
        "name": "w1"
      },
      {
        "name": "w2"
      }
    ]
  }

  ```

ACKs for top commit:
  ryanofsky:
    Code review ACK d44a261
  meshcollider:
    utACK d44a261

Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 15, 2023
…ctory

d44a261 Fix issues when `walletdir` is root directory (unknown)

Pull request description:

  + Remove one character less from wallet path

  + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin#21907 helped me resolve the issue.

  **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed

  **Solution**: `if` statement to check `walletdir` is a root directory

  Fixes: bitcoin#21510 bitcoin#21501
  Related PR: bitcoin#20080

  Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`:

  Before this PR:

  ```

  {
    "wallets": [
      {
        "name": "1"
      },
      {
        "name": "2"
      }
    ]
  }

  ```

  After this PR:
  ```
    "wallets": [
      {
        "name": "w1"
      },
      {
        "name": "w2"
      }
    ]
  }

  ```

ACKs for top commit:
  ryanofsky:
    Code review ACK d44a261
  meshcollider:
    utACK d44a261

Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2023
…ctory

d44a261 Fix issues when `walletdir` is root directory (unknown)

Pull request description:

  + Remove one character less from wallet path

  + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin#21907 helped me resolve the issue.

  **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed

  **Solution**: `if` statement to check `walletdir` is a root directory

  Fixes: bitcoin#21510 bitcoin#21501
  Related PR: bitcoin#20080

  Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`:

  Before this PR:

  ```

  {
    "wallets": [
      {
        "name": "1"
      },
      {
        "name": "2"
      }
    ]
  }

  ```

  After this PR:
  ```
    "wallets": [
      {
        "name": "w1"
      },
      {
        "name": "w2"
      }
    ]
  }

  ```

ACKs for top commit:
  ryanofsky:
    Code review ACK d44a261
  meshcollider:
    utACK d44a261

Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2023
…ctory

d44a261 Fix issues when `walletdir` is root directory (unknown)

Pull request description:

  + Remove one character less from wallet path

  + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin#21907 helped me resolve the issue.

  **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed

  **Solution**: `if` statement to check `walletdir` is a root directory

  Fixes: bitcoin#21510 bitcoin#21501
  Related PR: bitcoin#20080

  Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`:

  Before this PR:

  ```

  {
    "wallets": [
      {
        "name": "1"
      },
      {
        "name": "2"
      }
    ]
  }

  ```

  After this PR:
  ```
    "wallets": [
      {
        "name": "w1"
      },
      {
        "name": "w2"
      }
    ]
  }

  ```

ACKs for top commit:
  ryanofsky:
    Code review ACK d44a261
  meshcollider:
    utACK d44a261

Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
UdjinM6 pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 16, 2023
…ctory

d44a261 Fix issues when `walletdir` is root directory (unknown)

Pull request description:

  + Remove one character less from wallet path

  + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin#21907 helped me resolve the issue.

  **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed

  **Solution**: `if` statement to check `walletdir` is a root directory

  Fixes: bitcoin#21510 bitcoin#21501
  Related PR: bitcoin#20080

  Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`:

  Before this PR:

  ```

  {
    "wallets": [
      {
        "name": "1"
      },
      {
        "name": "2"
      }
    ]
  }

  ```

  After this PR:
  ```
    "wallets": [
      {
        "name": "w1"
      },
      {
        "name": "w2"
      }
    ]
  }

  ```

ACKs for top commit:
  ryanofsky:
    Code review ACK d44a261
  meshcollider:
    utACK d44a261

Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
@bitcoin bitcoin locked and limited conversation to collaborators Jun 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when opening wallet UI Hangs when running as std user wallet: Can't Access System Volume Information
6 participants