Skip to content

wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree#15583

Merged
laanwj merged 1 commit intobitcoin:masterfrom
promag:2019-03-fix-listwalletdir
Mar 14, 2019
Merged

wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree#15583
laanwj merged 1 commit intobitcoin:masterfrom
promag:2019-03-fix-listwalletdir

Conversation

@promag
Copy link
Contributor

@promag promag commented Mar 11, 2019

Use the noexcept members of boost::filesystem::recursive_directory_iterator in order to ignore boost::filesystem::directory_iterator::construct: Permission denied errors. The errors are logged though.

Steps to reproduce the issue:

# 1. create directory for -walletdir without read access:
mkdir /tmp/foo && chmod a-r /tmp/foo

# 2. run bitcoin-qt and should print an error, but continues running:
/Volumes/Bitcoin-Core/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt -regtest -walletdir=/tmp/foo
/private/tmp/foo: Permission denied

# 4. go to File -> Open Wallet and should segfault:
EXCEPTION: N5boost10filesystem16filesystem_errorE
boost::filesystem::directory_iterator::construct: Permission denied: "/private/tmp/foo"
bitcoin in Runaway exception

@promag
Copy link
Contributor Author

promag commented Mar 11, 2019

Fixes #15555 (comment).

@hebasto
Copy link
Member

hebasto commented Mar 11, 2019

Concept ACK.

@fanquake fanquake added this to the 0.18.0 milestone Mar 11, 2019
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK 8de53d5097c7e0936a15ec738e2580814ee0de9b. Nice fix. I wouldn't have expected incrementing the iterator to throw.

If there's an easy way to add a test, it could be nice to have. But if it requires adding something platform-specific, probably better to skip.

@promag
Copy link
Contributor Author

promag commented Mar 12, 2019

If there's an easy way to add a test, it could be nice to have.

I'd like to confirm a gitian build first, cc @MarcoFalke.

@promag
Copy link
Contributor Author

promag commented Mar 12, 2019

Thanks @fanquake!

@Sjors
Copy link
Member

Sjors commented Mar 12, 2019

Thanks for catching this @kiv06041992. I was able to reproduce with v0.18.0rc1 binary, as well as when building master from source.

This commit fixes it, so tACK 8de53d5097 (test would be nice).

I'm even able to create a new wallet and use it, and the wallet will be hidden next time you start (no idea why one would want that).

@promag can you copy the steps to reproduce to the description?

@promag
Copy link
Contributor Author

promag commented Mar 12, 2019

@promag can you copy the steps to reproduce to the description?

Done.

@promag promag force-pushed the 2019-03-fix-listwalletdir branch 2 times, most recently from df3d9d2 to 4c61be6 Compare March 12, 2019 23:53
@laanwj
Copy link
Member

laanwj commented Mar 13, 2019

Although I agree that the current behavior is undesirable, I don't like ignoring errors either. In my experience this makes troubleshooting as good as impossible when something unexpected happens. Please handle the error or at least log it.

@promag
Copy link
Contributor Author

promag commented Mar 13, 2019

@laanwj agree, I'll log.

@ryanofsky
Copy link
Contributor

ryanofsky commented Mar 13, 2019

Maybe break on failure to increment, since that might result in an infinite loop.

EDIT: It looks like failing to increment shouldn't cause infinite loops since m_imp->increment(&ec) is called unconditionally in https://www.boost.org/doc/libs/1_69_0/boost/filesystem/operations.hpp and end condition is based an internal stack.

@promag
Copy link
Contributor Author

promag commented Mar 13, 2019

Now logging the error and the respective path. Also log error in IsBerkeleyBtree. Will squash after review.

@promag promag changed the title wallet: Ignore recursive_directory_iterator errors in ListWalletDir wallet: Log errors in ListWalletDir and IsBerkeleyBtree Mar 13, 2019
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK d595965c599161b14346a2552867eb2869a097c7. Only change since last review is adding logging. Current PR description ("Log errors in ListWalletDir and IsBerkeleyBtree") seems misleading, though. Main change is not the logging, but making listwalletdir not throw exceptions.

@DrahtBot
Copy link
Contributor

Gitian builds for commit c3b1cb9 (master):

Gitian builds for commit dab434cdc7d30fef582530766a8d93b93da3ee66 (master and this pull):

@laanwj
Copy link
Member

laanwj commented Mar 13, 2019

Now logging the error and the respective path. Also log error in IsBerkeleyBtree. Will squash after review.

Thank you, looks good to me now, utACK after squash

@promag promag force-pushed the 2019-03-fix-listwalletdir branch from d595965 to 15c69b1 Compare March 13, 2019 20:43
@promag promag changed the title wallet: Log errors in ListWalletDir and IsBerkeleyBtree wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree Mar 13, 2019
@promag
Copy link
Contributor Author

promag commented Mar 13, 2019

Reworded and squashed, thanks.

@laanwj laanwj merged commit 15c69b1 into bitcoin:master Mar 14, 2019
laanwj pushed a commit that referenced this pull request Mar 14, 2019
Github-Pull: #15583
Rebased-From: 15c69b1
Tree-SHA512: edef7cafc5a2cb8d3355591a7742ef61454a5dedbb1dc22f6cc6bae42329d887f3f4a054f2aeedf31180051f50b6478d09e204066205699dabc0cb67b0ce4a96
laanwj added a commit that referenced this pull request Mar 14, 2019
…rkeleyBtree

15c69b1 wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree (João Barbosa)

Pull request description:

  Use the `noexcept` members of `boost::filesystem::recursive_directory_iterator` in order to ignore `boost::filesystem::directory_iterator::construct: Permission denied` errors. The errors are logged though.

  Steps to reproduce the issue:

  ```sh
  # 1. create directory for -walletdir without read access:
  mkdir /tmp/foo && chmod a-r /tmp/foo

  # 2. run bitcoin-qt and should print an error, but continues running:
  /Volumes/Bitcoin-Core/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt -regtest -walletdir=/tmp/foo
  /private/tmp/foo: Permission denied

  # 4. go to File -> Open Wallet and should segfault:
  EXCEPTION: N5boost10filesystem16filesystem_errorE
  boost::filesystem::directory_iterator::construct: Permission denied: "/private/tmp/foo"
  bitcoin in Runaway exception
  ```

Tree-SHA512: 37e8bf5a1e0defc331030fd511bf9cac2765d01dfbf23e7233f37506e85b8ad07edcde9ba6dae7a2c95700c78d28c7dd248153607381852da96273cb159c4934
@DrahtBot
Copy link
Contributor

Gitian builds for commit 8e1704c (master):

Gitian builds for commit f5095fb13a91f7a5eccb7230803bb7aeaf686ab9 (master and this pull):

HashUnlimited pushed a commit to HashUnlimited/chaincoin that referenced this pull request Apr 19, 2019
Github-Pull: bitcoin#15583
Rebased-From: 15c69b1
Tree-SHA512: edef7cafc5a2cb8d3355591a7742ef61454a5dedbb1dc22f6cc6bae42329d887f3f4a054f2aeedf31180051f50b6478d09e204066205699dabc0cb67b0ce4a96
@promag promag deleted the 2019-03-fix-listwalletdir branch April 22, 2019 00:15
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 4, 2020
…sBerkeleyBtree

Summary:
wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree (João Barbosa)

Pull request description:

  Use the `noexcept` members of `boost::filesystem::recursive_directory_iterator` in order to ignore `boost::filesystem::directory_iterator::construct: Permission denied` errors. The errors are logged though.

  Steps to reproduce the issue:

  ```sh
  # 1. create directory for -walletdir without read access:
  mkdir /tmp/foo && chmod a-r /tmp/foo

  # 2. run bitcoin-qt and should print an error, but continues running:
  /Volumes/Bitcoin-Core/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt -regtest -walletdir=/tmp/foo
  /private/tmp/foo: Permission denied

  # 4. go to File -> Open Wallet and should segfault:
  EXCEPTION: N5boost10filesystem16filesystem_errorE
  boost::filesystem::directory_iterator::construct: Permission denied: "/private/tmp/foo"
  bitcoin in Runaway exception
  ```

---

Backport of Core [[bitcoin/bitcoin#15583 | PR15583]]

Test Plan:
  ninja check check-functional

run bitcoin-qt with a read-only -walletdir, do not segfault when hovering over 'create wallet'

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7350
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 11, 2021
…nd IsBerkeleyBtree

15c69b1 wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree (João Barbosa)

Pull request description:

  Use the `noexcept` members of `boost::filesystem::recursive_directory_iterator` in order to ignore `boost::filesystem::directory_iterator::construct: Permission denied` errors. The errors are logged though.

  Steps to reproduce the issue:

  ```sh
  # 1. create directory for -walletdir without read access:
  mkdir /tmp/foo && chmod a-r /tmp/foo

  # 2. run bitcoin-qt and should print an error, but continues running:
  /Volumes/Bitcoin-Core/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt -regtest -walletdir=/tmp/foo
  /private/tmp/foo: Permission denied

  # 4. go to File -> Open Wallet and should segfault:
  EXCEPTION: N5boost10filesystem16filesystem_errorE
  boost::filesystem::directory_iterator::construct: Permission denied: "/private/tmp/foo"
  bitcoin in Runaway exception
  ```

Tree-SHA512: 37e8bf5a1e0defc331030fd511bf9cac2765d01dfbf23e7233f37506e85b8ad07edcde9ba6dae7a2c95700c78d28c7dd248153607381852da96273cb159c4934
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants