build: fix build with no sqlite3 support.
What changed, and why it matters
This is a build-fix patch for a single test file. It rearranges code so that the bookkeeping plugin's unit test compiles and runs correctly when Core Lightning is built without SQLite3 support. When SQLite3 is absent, the test now simply does nothing instead of failing to compile. There is no security vulnerability here.
No security action needed. Treat as a normal build/test maintenance fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit moves SQLite3-dependent declarations, global variables, and functions inside a #if HAVE_SQLITE3 guard, and provides stub implementations of jsonrpc_request_sync and main for the no-SQLite3 case. It also relocates shared mock helpers (jsonrpc_set_datastore_, ignore_datastore_reply, json_out_obj) outside the conditional block so they are available in both configurations. This resolves a build failure reported in issue #8473.
Changed components
plugins/bkpr/test/run-recorder.cInspect captured patch +76 / −67
diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c
index af8802e6..da01849f 100644
--- a/plugins/bkpr/test/run-recorder.c
+++ b/plugins/bkpr/test/run-recorder.c
@@ -37,10 +37,6 @@
#include "plugins/bkpr/rebalances.c"
#include "plugins/bkpr/sql.c"
-#if HAVE_SQLITE3
- #include <sqlite3.h>
-#endif
-
/* AUTOGENERATED MOCKS START */
/* Generated stub for chain_event_description */
const char *chain_event_description(const struct bkpr *bkpr UNNEEDED,
@@ -89,6 +85,55 @@ void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char
{ fprintf(stderr, "plugin_log called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
+struct command_result *jsonrpc_set_datastore_(struct command *cmd UNNEEDED,
+ const char *path UNNEEDED,
+ const void *value UNNEEDED,
+ int len_or_str UNNEEDED,
+ const char *mode UNNEEDED,
+ struct command_result *(*cb)(struct command *command,
+ const char *method,
+ const char *buf,
+ const jsmntok_t *result,
+ void *arg),
+ struct command_result *(*errcb)(struct command *command UNNEEDED,
+ const char *method UNNEEDED,
+ const char *buf UNNEEDED,
+ const jsmntok_t *result UNNEEDED,
+ void *arg) UNNEEDED,
+ void *arg)
+
+{
+ return cb(cmd, NULL, NULL, NULL, arg);
+}
+
+struct command_result *ignore_datastore_reply(struct command *cmd,
+ const char *method UNNEEDED,
+ const char *buf UNNEEDED,
+ const jsmntok_t *result UNNEEDED,
+ void *arg UNNEEDED)
+{
+ return NULL;
+}
+
+struct json_out *json_out_obj(const tal_t *ctx,
+ const char *fieldname,
+ const char *str)
+{
+ struct json_out *jout = json_out_new(ctx);
+ json_out_start(jout, NULL, '{');
+ if (str)
+ json_out_addstr(jout, fieldname, str);
+ if (taken(str))
+ tal_free(str);
+ json_out_end(jout, '}');
+ json_out_finished(jout);
+
+ return jout;
+}
+
+#if HAVE_SQLITE3
+#include <sqlite3.h>
+
static sqlite3 *bkpr_db;
static struct command *cmd;
@@ -425,59 +470,12 @@ static void log_channel_event(sqlite3 *db,
sqlite3_finalize(stmt);
}
-struct command_result *jsonrpc_set_datastore_(struct command *cmd UNNEEDED,
- const char *path UNNEEDED,
- const void *value UNNEEDED,
- int len_or_str UNNEEDED,
- const char *mode UNNEEDED,
- struct command_result *(*cb)(struct command *command,
- const char *method,
- const char *buf,
- const jsmntok_t *result,
- void *arg),
- struct command_result *(*errcb)(struct command *command UNNEEDED,
- const char *method UNNEEDED,
- const char *buf UNNEEDED,
- const jsmntok_t *result UNNEEDED,
- void *arg) UNNEEDED,
- void *arg)
-
-{
- return cb(cmd, NULL, NULL, NULL, arg);
-}
-
-struct command_result *ignore_datastore_reply(struct command *cmd,
- const char *method UNNEEDED,
- const char *buf UNNEEDED,
- const jsmntok_t *result UNNEEDED,
- void *arg UNNEEDED)
-{
- return NULL;
-}
-
-struct json_out *json_out_obj(const tal_t *ctx,
- const char *fieldname,
- const char *str)
-{
- struct json_out *jout = json_out_new(ctx);
- json_out_start(jout, NULL, '{');
- if (str)
- json_out_addstr(jout, fieldname, str);
- if (taken(str))
- tal_free(str);
- json_out_end(jout, '}');
- json_out_finished(jout);
-
- return jout;
-}
-
const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
struct command *cmd,
const char *method,
const struct json_out *params TAKES,
const char **resp)
{
-#if HAVE_SQLITE3
sqlite3_stmt *s;
jsmntok_t *toks;
jsmn_parser parser;
@@ -551,9 +549,6 @@ done:
tal_free(params);
*resp = buf;
return toks;
-#else
- return NULL;
-#endif
}
static char *tmp_dsn(const tal_t *ctx)
@@ -1660,21 +1655,35 @@ int main(int argc, char *argv[])
common_setup(argv[0]);
- if (HAVE_SQLITE3) {
- /* UBSan insists cmd isn't NULL */
- cmd = tal(tmpctx, struct command);
- ok &= test_account_crud(tmpctx);
- ok &= test_channel_event_crud(tmpctx);
- ok &= test_chain_event_crud(tmpctx);
- ok &= test_account_balances(tmpctx);
- ok &= test_onchain_fee_chan_close(tmpctx);
- ok &= test_onchain_fee_chan_open(tmpctx);
- ok &= test_channel_rebalances(tmpctx);
- ok &= test_onchain_fee_wallet_spend(tmpctx);
- sqlite3_close(bkpr_db);
- }
+ /* UBSan insists cmd isn't NULL */
+ cmd = tal(tmpctx, struct command);
+ ok &= test_account_crud(tmpctx);
+ ok &= test_channel_event_crud(tmpctx);
+ ok &= test_chain_event_crud(tmpctx);
+ ok &= test_account_balances(tmpctx);
+ ok &= test_onchain_fee_chan_close(tmpctx);
+ ok &= test_onchain_fee_chan_open(tmpctx);
+ ok &= test_channel_rebalances(tmpctx);
+ ok &= test_onchain_fee_wallet_spend(tmpctx);
+ sqlite3_close(bkpr_db);
common_shutdown();
trace_cleanup();
return !ok;
}
+#else /* No sqlite, no test! */
+const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
+ struct command *cmd,
+ const char *method,
+ const struct json_out *params TAKES,
+ const char **resp)
+{
+ abort();
+}
+
+int main(int argc, char *argv[])
+{
+ common_setup(argv[0]);
+ common_shutdown();
+}
+#endif /* !HAVE_SQLITE3 */
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.