Skip to content

Commit

Permalink
fuzz: Don't compile BDB-specific code on MSVC in wallet_bdb_parser.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 2, 2024
1 parent 3f1d82a commit 60f2120
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/wallet/test/fuzz/wallet_bdb_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
#include <fstream>
#include <iostream>

// There is an inconsistency in BDB on Windows.
// See: https://github.com/bitcoin/bitcoin/pull/26606#issuecomment-2322763212
#undef USE_BDB_NON_MSVC
#if defined(USE_BDB) && !defined(_MSC_VER)
#define USE_BDB_NON_MSVC
#endif

using wallet::DatabaseOptions;
using wallet::DatabaseStatus;

Expand Down Expand Up @@ -50,15 +57,15 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser)
}
g_setup->m_args.ForceSetArg("-dumpfile", fs::PathToString(bdb_ro_dumpfile));

#ifdef USE_BDB
#ifdef USE_BDB_NON_MSVC
bool bdb_ro_err = false;
bool bdb_ro_strict_err = false;
#endif
auto db{MakeBerkeleyRODatabase(wallet_path, options, status, error)};
if (db) {
assert(DumpWallet(g_setup->m_args, *db, error));
} else {
#ifdef USE_BDB
#ifdef USE_BDB_NON_MSVC
bdb_ro_err = true;
#endif
if (error.original.starts_with("AutoFile::ignore: end of file") ||
Expand Down Expand Up @@ -90,15 +97,15 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser)
error.original == "Subdatabase has an unexpected name" ||
error.original == "Unsupported BDB data file version number" ||
error.original == "BDB builtin encryption is not supported") {
#ifdef USE_BDB
#ifdef USE_BDB_NON_MSVC
bdb_ro_strict_err = true;
#endif
} else {
throw std::runtime_error(error.original);
}
}

#ifdef USE_BDB
#ifdef USE_BDB_NON_MSVC
// Try opening with BDB
fs::path bdb_dumpfile{g_setup->m_args.GetDataDirNet() / "fuzzed_dumpfile_bdb.dump"};
if (fs::exists(bdb_dumpfile)) { // Writing into an existing dump file will throw an exception
Expand Down

0 comments on commit 60f2120

Please sign in to comment.