Skip to content

Conversation

ken2812221
Copy link
Contributor

@ken2812221 ken2812221 commented Oct 23, 2018

Fix #14538

Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

throw std::runtime_error(strprintf("BerkeleyBatch: Can't open database %s (duplicates fileid %s from %s)", filename,

But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

if (pdb == nullptr) {

Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

error_string = strprintf("Error loading wallet %s. Duplicate -wallet filename specified.", location.GetName());

This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

@ken2812221 ken2812221 changed the title wallet: throw an error if user load the wallet file by different ways wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. Oct 23, 2018
@ryanofsky
Copy link
Contributor

Would prefer to check this at database level, rather than in higher level wallet code. I think it's better if high level code just passes along wallet paths and isn't concerned with how data is stored in them.

I posted a tweaked version of this PR at 40a6475 which moves the check. @ken2812221, could you incorporate 40a6475 into this PR if you think it makes sense?

@ken2812221
Copy link
Contributor Author

ken2812221 commented Oct 23, 2018

@ryanofsky The element in mapDb is not always exist.

For example:

  1. Load wallet dir/w1
  2. Load wallet dir/w2
  3. Unload wallet dir/w1

Now mapDb contains neither dir/w1 nor dir/w2 because it would flush all wallet files that share same BerkeleyEnvironment

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 23, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #11911 (Free BerkeleyEnvironment instances when not in use by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@ryanofsky
Copy link
Contributor

@ryanofsky The element in mapDb is not always exist.

Good catch. I think a small refactoring could fix this: 9c945d0. And then the fix would change slightly to aef19be.

I pushed a branch with these two commits to: https://github.com/ryanofsky/bitcoin/commits/pr/bloaded

I think this is a better than checking for wallet.dat files outside the database layer, but let me know what you think, and feel free to use the code or commits in this PR if you think this approach makes sense.

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 aef19be

@ken2812221 ken2812221 changed the title wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. wallet: detecting duplicate wallet by comparing the db file. Oct 26, 2018
@ken2812221 ken2812221 changed the title wallet: detecting duplicate wallet by comparing the db file. wallet: detecting duplicate wallet by comparing the db filename. Oct 30, 2018
@ken2812221
Copy link
Contributor Author

Rebased

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 b0375538375eb0c419b308d1015723ab64d53294. Only change since last review is rebase.

@promag, this might be an easy PR for to you review. First commit is just refactoring that doesn't change behavior. Second commit is the actual fix.

@ken2812221, it might help for this to have a more complete PR description.


Suggested PR description:

Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

throw std::runtime_error(strprintf("BerkeleyBatch: Can't open database %s (duplicates fileid %s from %s)", filename,

But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

if (pdb == nullptr) {

Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

error_string = strprintf("Error loading wallet %s. Duplicate -wallet filename specified.", location.GetName());

This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

@ken2812221
Copy link
Contributor Author

@ryanofsky Thanks for your review. I would take your suggestion.

@@ -463,7 +463,8 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo
if (!env->Open(false /* retry */))
throw std::runtime_error("BerkeleyBatch: Failed to open database environment.");

pdb = env->mapDb[strFilename];
BerkeleyDatabase& database = env->m_databases.at(strFilename).get();
Copy link
Contributor

@promag promag Nov 5, 2018

Choose a reason for hiding this comment

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

Some comments here:

  • there's a slight change when replacing map::operator[] with map::at, maybe worth a comemnt or an assertion?
  • also, isn't this equivalent to the above database argument?
  • if this is really necessary then you could avoid shadowing database.

Copy link
Contributor

Choose a reason for hiding this comment

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

re: #14552 (comment)

Oh, I didn't even realize there was a database argument being shadowed above. Should just delete this line and use the existing database, which points to the same thing.

if (mock) {
env->Close();
env->Reset();
env->MakeMock();
}
}

~BerkeleyDatabase() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, could add final to class since this is not virtual.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

final can only be added to virtual method.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ken2812221 I mean class BerkeleyDatabase final.

Copy link
Contributor

Choose a reason for hiding this comment

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

Change would be unrelated to this PR, and IMO, it's better only to use final when you have virtual methods and actual optimizations this would allow or bugs it would prevent. There's a core guideline that touches on this: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-final

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice thanks.

@@ -56,9 +56,8 @@ bool WalletDatabaseFileId::operator==(const WalletDatabaseFileId& rhs) const
return memcmp(value, &rhs.value, sizeof(value)) == 0;
}

BerkeleyEnvironment* GetWalletEnv(const fs::path& wallet_path, std::string& database_filename)
void SplitWalletPath(const fs::path& wallet_path, fs::path& env_directory, std::string& database_filename)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be static?

@@ -563,12 +581,11 @@ void BerkeleyEnvironment::CloseDb(const std::string& strFile)
{
{
LOCK(cs_db);
if (mapDb[strFile] != nullptr) {
BerkeleyDatabase& database = m_databases.at(strFile).get();
Copy link
Contributor

@promag promag Nov 5, 2018

Choose a reason for hiding this comment

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

Same as above, there's a slight change when replacing map::operator[] with map::at, maybe worth a comment or an assertion?

ryanofsky and others added 2 commits November 6, 2018 08:28
This is a refactoring change that doesn't affect behavior. The motivation
behind the change is give BerkeleyEnvironment objects access to
BerkeleyDatabase objects so it will be possible to simplify the duplicate
wallet check and more reliably avoid opening the same databases twice.
@promag
Copy link
Contributor

promag commented Nov 6, 2018

utACK 15c93f0.

LOCK(cs_db);
auto env = g_dbenvs.find(env_directory.string());
if (env == g_dbenvs.end()) return false;
auto db = env->second.m_databases.find(database_filename);
Copy link
Member

@laanwj laanwj Nov 6, 2018

Choose a reason for hiding this comment

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

I think this is leaking the implementation detail of m_databases, wouldn't checking whether a database exists ideally be a responsibility of the database environment. e.g. add a bool IsDatabaseLoaded(name) on DBenv?

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that BerkeleyEnvironment::mapDb is currently used outside. I consider this a bugfix so any improvement/refactor could come next.

Copy link
Contributor

@ryanofsky ryanofsky Nov 8, 2018

Choose a reason for hiding this comment

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

This is now resolved (by adding IsDatabaseLoaded)

@ryanofsky
Copy link
Contributor

utACK 5912031. Just minor tweaks since last review: replacing map::at exception with assert, adding IsDatabaseLoaded.

@promag and @MarcoFalke, I've noticed that in your recent reviews you've been advocating replacing exceptions with asserts or return codes. Maybe one of you can write up some guidelines about when to use exceptions in the developer guide. Personally, I tend to like exceptions and think that whatever drawbacks they have will be fixed by new c++ features like throws/std::error in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf (see §4.1.1 "Elevator Pitch")

@meshcollider
Copy link
Contributor

utACK 5912031, looks good

@ryanofsky
Copy link
Contributor

Can this be merged? It fixes an ugly bug and has some refactoring changes I want to build on. If it can't be merged, maybe it could be added to https://github.com/bitcoin/bitcoin/projects/8

@maflcko
Copy link
Member

maflcko commented Nov 15, 2018

Is this for backport?

jonspock pushed a commit to jonspock/devault that referenced this pull request Mar 24, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Apr 6, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Apr 8, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Apr 8, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Apr 8, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Apr 8, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Apr 9, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Apr 17, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request May 23, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request May 25, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Jul 9, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Jul 10, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Jul 17, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Jul 17, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Jul 20, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Jul 29, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Jul 31, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to devaultcrypto/devault that referenced this pull request Aug 5, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to devaultcrypto/devault that referenced this pull request Aug 6, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
jonspock pushed a commit to jonspock/devault that referenced this pull request Aug 7, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
proteanx pushed a commit to devaultcrypto/devault that referenced this pull request Aug 8, 2020
Summary:
```
Fix crash attempting to load the same wallet with different path strings
that resolve to the same absolute path.
```
More details here:
bitcoin/bitcoin#14552

Backport of core PR14552:
https://github.com/bitcoin/bitcoin/pull/14552/files

Depends on D4885.

Test Plan:
  ninja check
  ./test/functional/test_runner.py wallet_*

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4886
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Apr 4, 2021
…the db filename.

5912031 wallet: Create IsDatabaseLoaded function (Chun Kuan Lee)
15c93f0 wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. (Chun Kuan Lee)
c456fbd Refactor: Move m_db pointers into BerkeleyDatabase (Russell Yanofsky)

Pull request description:

  Fix bitcoin#14538

  Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L44

  But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L467

  Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/wallet.cpp#L3853

  This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

Tree-SHA512: 2fa01811c160b57be3b76c6b4983556a04bbce71a3f8202429987ec020664a062e897deedcd9248bc04e9baaa2fc7b464e2595dcaeff2af0818387bf1fcdbf6f
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Apr 4, 2021
…the db filename.

5912031 wallet: Create IsDatabaseLoaded function (Chun Kuan Lee)
15c93f0 wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. (Chun Kuan Lee)
c456fbd Refactor: Move m_db pointers into BerkeleyDatabase (Russell Yanofsky)

Pull request description:

  Fix bitcoin#14538

  Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L44

  But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L467

  Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/wallet.cpp#L3853

  This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

Tree-SHA512: 2fa01811c160b57be3b76c6b4983556a04bbce71a3f8202429987ec020664a062e897deedcd9248bc04e9baaa2fc7b464e2595dcaeff2af0818387bf1fcdbf6f
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Apr 4, 2021
…the db filename.

5912031 wallet: Create IsDatabaseLoaded function (Chun Kuan Lee)
15c93f0 wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. (Chun Kuan Lee)
c456fbd Refactor: Move m_db pointers into BerkeleyDatabase (Russell Yanofsky)

Pull request description:

  Fix bitcoin#14538

  Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L44

  But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L467

  Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/wallet.cpp#L3853

  This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

Tree-SHA512: 2fa01811c160b57be3b76c6b4983556a04bbce71a3f8202429987ec020664a062e897deedcd9248bc04e9baaa2fc7b464e2595dcaeff2af0818387bf1fcdbf6f
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Apr 4, 2021
…the db filename.

5912031 wallet: Create IsDatabaseLoaded function (Chun Kuan Lee)
15c93f0 wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. (Chun Kuan Lee)
c456fbd Refactor: Move m_db pointers into BerkeleyDatabase (Russell Yanofsky)

Pull request description:

  Fix bitcoin#14538

  Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L44

  But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L467

  Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/wallet.cpp#L3853

  This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

Tree-SHA512: 2fa01811c160b57be3b76c6b4983556a04bbce71a3f8202429987ec020664a062e897deedcd9248bc04e9baaa2fc7b464e2595dcaeff2af0818387bf1fcdbf6f
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Apr 5, 2021
…the db filename.

5912031 wallet: Create IsDatabaseLoaded function (Chun Kuan Lee)
15c93f0 wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. (Chun Kuan Lee)
c456fbd Refactor: Move m_db pointers into BerkeleyDatabase (Russell Yanofsky)

Pull request description:

  Fix bitcoin#14538

  Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L44

  But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L467

  Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/wallet.cpp#L3853

  This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

Tree-SHA512: 2fa01811c160b57be3b76c6b4983556a04bbce71a3f8202429987ec020664a062e897deedcd9248bc04e9baaa2fc7b464e2595dcaeff2af0818387bf1fcdbf6f
xdustinface pushed a commit to xdustinface/dash that referenced this pull request Apr 13, 2021
…the db filename.

5912031 wallet: Create IsDatabaseLoaded function (Chun Kuan Lee)
15c93f0 wallet: Add trailing wallet.dat when detecting duplicate wallet if it's a directory. (Chun Kuan Lee)
c456fbd Refactor: Move m_db pointers into BerkeleyDatabase (Russell Yanofsky)

Pull request description:

  Fix bitcoin#14538

  Fix crash attempting to load the same wallet with different path strings that resolve to the same absolute path. The primary check which prevents loading the same wallet twice is:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L44

  But this check is skipped if both wallet paths resolve to the same absolute path, due to caching here:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/db.cpp#L467

  Meanwhile a secondary check for duplicate wallets is not reliable because it based on a literal comparison, instead of comparison using absolute paths:

  https://github.com/bitcoin/bitcoin/blob/6b8d0a2164b30eab76e7bccb1ffb056a10fba406/src/wallet/wallet.cpp#L3853

  This PR fixes the latter check to compare the absolute path of a new wallet being loaded to absolute paths of wallets already loaded, so there should no longer be any way to load the same wallet more than once.

Tree-SHA512: 2fa01811c160b57be3b76c6b4983556a04bbce71a3f8202429987ec020664a062e897deedcd9248bc04e9baaa2fc7b464e2595dcaeff2af0818387bf1fcdbf6f
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 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.

loadwallet command crashes bitcoind
8 participants