Fix: nullptr resolving without db config (#6029)

If the config disables SQL db usage, such as a validator:

```
[ledger_tx_tables]
use_tx_tables = 0
```

then the pointer to DB engine is null, but it was still resolved during startup. Although it didn't crash in Release mode, possibly due to the compiler optimizing it away, it did crash in Debug mode. This change explicitly checks for the validity of the pointer and generates a runtime error if not set.
This commit is contained in:
Olek
2025-11-21 17:20:45 -05:00
committed by GitHub
parent 58e03190ac
commit 8449c6c365
3 changed files with 12 additions and 5 deletions

View File

@@ -171,7 +171,7 @@ getRowsMinMax(soci::session& session, TableType type)
bool
saveValidatedLedger(
DatabaseCon& ldgDB,
DatabaseCon& txnDB,
std::unique_ptr<DatabaseCon> const& txnDB,
Application& app,
std::shared_ptr<Ledger const> const& ledger,
bool current)
@@ -254,7 +254,15 @@ saveValidatedLedger(
if (app.config().useTxTables())
{
auto db = txnDB.checkoutDb();
if (!txnDB)
{
// LCOV_EXCL_START
JLOG(j.fatal()) << "TxTables db isn't available";
Throw<std::runtime_error>("TxTables db isn't available");
// LCOV_EXCL_STOP
}
auto db = txnDB->checkoutDb();
soci::transaction tr(*db);

View File

@@ -111,7 +111,7 @@ getRowsMinMax(soci::session& session, TableType type);
bool
saveValidatedLedger(
DatabaseCon& ldgDB,
DatabaseCon& txnDB,
std::unique_ptr<DatabaseCon> const& txnDB,
Application& app,
std::shared_ptr<Ledger const> const& ledger,
bool current);

View File

@@ -392,8 +392,7 @@ SQLiteDatabaseImp::saveValidatedLedger(
{
if (existsLedger())
{
if (!detail::saveValidatedLedger(
*lgrdb_, *txdb_, app_, ledger, current))
if (!detail::saveValidatedLedger(*lgrdb_, txdb_, app_, ledger, current))
return false;
}