Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 4: [PATCH 04/68] fix(wallet): preserve Roots database hardening on Core 30.3

src/wallet/db.cpp

Before: src/wallet/db.cpp · After: src/wallet/db.cpp

File metadata
index 781b6fa461dcccdd7733d5409e7a0be80feade02..237aa6acc1987d03fb4292890742a33dda97b7a1 100644

Download original patch · Release notes

Diff rows 1–58 of 58. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

src/wallet/db.cpp CHANGED
@@ -7,11 +7,13 @@
7
  #include <common/args.h>
8
  #include <logging.h>
9
  #include <util/fs.h>
 
10
  #include <wallet/db.h>
11
 
12
  #include <algorithm>
13
  #include <exception>
14
  #include <fstream>
 
15
  #include <string>
16
  #include <system_error>
17
  #include <vector>
@@ -22,14 +24,45 @@ bool operator<(std::span<const std::byte> a, BytePrefix b) { return std::ranges:
22
 
23
  std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wallet_dir)
24
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  std::vector<std::pair<fs::path, std::string>> paths;
26
  std::error_code ec;
27
 
28
  for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
29
  assert(!ec); // Loop should exit on error.
 
 
 
 
 
 
 
30
  try {
31
  const fs::path path{it->path().lexically_relative(wallet_dir)};
32
 
 
 
 
 
 
33
  if (it->status().type() == fs::file_type::directory) {
34
  if (IsBDBFile(BDBDataFile(it->path()))) {
35
  // Found a directory which contains wallet.dat btree file, add it as a wallet with BERKELEY format.
 
7
  #include <common/args.h>
8
  #include <logging.h>
9
  #include <util/fs.h>
10
+ #include <util/fs_helpers.h>
11
  #include <wallet/db.h>
12
 
13
  #include <algorithm>
14
  #include <exception>
15
  #include <fstream>
16
+ #include <set>
17
  #include <string>
18
  #include <system_error>
19
  #include <vector>
 
24
 
25
  std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wallet_dir)
26
  {
27
+ const fs::path& data_dir = gArgs.GetDataDirNet();
28
+ const fs::path& blocks_dir = gArgs.GetBlocksDirPath();
29
+
30
+ // Here we place the top level dirs we want to skip in case walletdir is datadir or blocksdir
31
+ // Those directories are referenced in doc/files.md
32
+ const std::set<fs::path> ignore_paths = {
33
+ blocks_dir,
34
+ data_dir / "blktree",
35
+ data_dir / "blocks",
36
+ data_dir / "chainstate",
37
+ data_dir / "coins",
38
+ data_dir / "database",
39
+ data_dir / "indexes",
40
+ data_dir / "regtest",
41
+ data_dir / "signet",
42
+ data_dir / "testnet3",
43
+ data_dir / "testnet4"
44
+ };
45
+
46
  std::vector<std::pair<fs::path, std::string>> paths;
47
  std::error_code ec;
48
 
49
  for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
50
  assert(!ec); // Loop should exit on error.
51
+
52
+ // We don't want to iterate through those special node dirs
53
+ if (ignore_paths.count(it->path())) {
54
+ it.disable_recursion_pending();
55
+ continue;
56
+ }
57
+
58
  try {
59
  const fs::path path{it->path().lexically_relative(wallet_dir)};
60
 
61
+ if (IsSymlink(it->path())) {
62
+ LogWarning("Not recursively searching symlink/reparse point at '%s'", fs::PathToString(it->path()));
63
+ it.disable_recursion_pending();
64
+ }
65
+
66
  if (it->status().type() == fs::file_type::directory) {
67
  if (IsBDBFile(BDBDataFile(it->path()))) {
68
  // Found a directory which contains wallet.dat btree file, add it as a wallet with BERKELEY format.