5#include <bitcoin-build-config.h>
23#undef USE_BDB_NON_MSVC
24#if defined(USE_BDB) && !defined(_MSC_VER)
25#define USE_BDB_NON_MSVC
37 static auto testing_setup = MakeNoLogFileContext<TestingSetup>();
38 g_setup = testing_setup.get();
43 const auto wallet_path = g_setup->m_args.GetDataDirNet() /
"fuzzed_wallet.dat";
47 outfile <<
Span{buffer};
54 fs::path bdb_ro_dumpfile{g_setup->m_args.GetDataDirNet() /
"fuzzed_dumpfile_bdb_ro.dump"};
56 remove(bdb_ro_dumpfile);
60#ifdef USE_BDB_NON_MSVC
61 bool bdb_ro_err =
false;
62 bool bdb_ro_strict_err =
false;
68#ifdef USE_BDB_NON_MSVC
71 if (error.
original.starts_with(
"AutoFile::ignore: end of file") ||
72 error.
original.starts_with(
"AutoFile::read: end of file") ||
73 error.
original.starts_with(
"AutoFile::seek: ") ||
74 error.
original ==
"Not a BDB file" ||
75 error.
original ==
"Unexpected page type, should be 9 (BTree Metadata)" ||
76 error.
original ==
"Unexpected database flags, should only be 0x20 (subdatabases)" ||
77 error.
original ==
"Unexpected outer database root page type" ||
78 error.
original ==
"Unexpected number of entries in outer database root page" ||
79 error.
original ==
"Subdatabase page number has unexpected length" ||
80 error.
original ==
"Unknown record type in records page" ||
81 error.
original ==
"Unknown record type in internal page" ||
82 error.
original ==
"Unexpected page size" ||
83 error.
original ==
"Unexpected page type" ||
84 error.
original ==
"Page number mismatch" ||
85 error.
original ==
"Bad btree level" ||
87 error.
original ==
"Meta page number mismatch" ||
88 error.
original ==
"Data record position not in page" ||
89 error.
original ==
"Internal record position not in page" ||
90 error.
original ==
"LSNs are not reset, this database is not completely flushed. Please reopen then close the database with a version that has BDB support" ||
91 error.
original ==
"Records page has odd number of records" ||
92 error.
original ==
"Bad overflow record page type") {
94 }
else if (error.
original ==
"Subdatabase last page is greater than database last page" ||
95 error.
original ==
"Page number is greater than database last page" ||
96 error.
original ==
"Last page number could not fit in file" ||
97 error.
original ==
"Subdatabase has an unexpected name" ||
98 error.
original ==
"Unsupported BDB data file version number" ||
99 error.
original ==
"BDB builtin encryption is not supported") {
100#ifdef USE_BDB_NON_MSVC
101 bdb_ro_strict_err =
true;
104 throw std::runtime_error(error.
original);
108#ifdef USE_BDB_NON_MSVC
110 fs::path bdb_dumpfile{g_setup->m_args.GetDataDirNet() /
"fuzzed_dumpfile_bdb.dump"};
112 remove(bdb_dumpfile);
118 if (bdb_ro_err && !db) {
122 if (bdb_ro_strict_err) {
128 }
catch (
const std::runtime_error& e) {
129 if (bdb_ro_err)
return;
135 std::ifstream bdb_ro_dump(bdb_ro_dumpfile, std::ios_base::binary | std::ios_base::in);
136 std::ifstream bdb_dump(bdb_dumpfile, std::ios_base::binary | std::ios_base::in);
138 std::istreambuf_iterator<char>(bdb_ro_dump.rdbuf()),
139 std::istreambuf_iterator<char>(),
140 std::istreambuf_iterator<char>(bdb_dump.rdbuf())));
Non-refcounted RAII wrapper for FILE*.
A Span is an object that can refer to a contiguous sequence of objects.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
FILE * fopen(const fs::path &p, const char *mode)
std::unique_ptr< BerkeleyDatabase > MakeBerkeleyDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Return object giving access to Berkeley database at specified path.
bool DumpWallet(const ArgsManager &args, WalletDatabase &db, bilingual_str &error)
std::unique_ptr< BerkeleyRODatabase > MakeBerkeleyRODatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Return object giving access to Berkeley Read Only database at specified path.
Testing setup that configures a complete environment.
FUZZ_TARGET(wallet_bdb_parser,.init=initialize_wallet_bdb_parser)
void initialize_wallet_bdb_parser()