bkpr: send a backtrace if we get a fatal db event.
What changed, and why it matters
This change only adds a diagnostic backtrace printout when the bookkeeper plugin hits a fatal database error. It does not fix a vulnerability or change any security boundary; it is a debugging aid for developers.
No security action required; treat as normal diagnostic improvement. Continue to monitor the underlying fatal db event causes separately if they indicate bugs.
Security signals we found
fatal-error path now emits a backtrace before terminating
no change to transaction semantics, authorization, or input validation
no memory-safety, cryptographic, or network-security changes
Evidence from the diff
The commit modifies plugins/bkpr/db.c so that the db_error handler, on fatal errors, calls send_backtrace(msg) before invoking plugin_err. It also adds matching stubs in two unit-test files. The change is purely observability/diagnostics and does not alter transaction handling, error handling outcome, or any trust assumption.
Changed components
plugins/bkpr/db.cplugins/bkpr/test/run-bkpr_db.cplugins/bkpr/test/run-recorder.cInspect captured patch +13 / −2
diff --git a/plugins/bkpr/db.c b/plugins/bkpr/db.c
index cee68bef..48b9fe67 100644
--- a/plugins/bkpr/db.c
+++ b/plugins/bkpr/db.c
@@ -1,5 +1,7 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
+#include <ccan/tal/str/str.h>
+#include <common/daemon.h>
#include <db/bindings.h>
#include <db/common.h>
#include <db/exec.h>
@@ -148,8 +150,11 @@ static bool db_migrate(struct plugin *p, struct db *db)
static void db_error(struct plugin *plugin, bool fatal, const char *fmt, va_list ap)
{
- if (fatal)
- plugin_errv(plugin, fmt, ap);
+ if (fatal) {
+ const char *msg = tal_vfmt(tmpctx, fmt, ap);
+ send_backtrace(msg);
+ plugin_err(plugin, "%s", msg);
+ }
else
plugin_logv(plugin, LOG_BROKEN, fmt, ap);
}
diff --git a/plugins/bkpr/test/run-bkpr_db.c b/plugins/bkpr/test/run-bkpr_db.c
index 46c3b4c9..e2ef6213 100644
--- a/plugins/bkpr/test/run-bkpr_db.c
+++ b/plugins/bkpr/test/run-bkpr_db.c
@@ -204,6 +204,9 @@ bool param_check(struct command *cmd UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t tokens[] UNNEEDED, ...)
{ fprintf(stderr, "param_check called!\n"); abort(); }
+/* Generated stub for send_backtrace */
+void send_backtrace(const char *why UNNEEDED)
+{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for toks_alloc */
jsmntok_t *toks_alloc(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "toks_alloc called!\n"); abort(); }
diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c
index b1d5c9b9..7b7e9aa6 100644
--- a/plugins/bkpr/test/run-recorder.c
+++ b/plugins/bkpr/test/run-recorder.c
@@ -210,6 +210,9 @@ bool param_check(struct command *cmd UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t tokens[] UNNEEDED, ...)
{ fprintf(stderr, "param_check called!\n"); abort(); }
+/* Generated stub for send_backtrace */
+void send_backtrace(const char *why UNNEEDED)
+{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for toks_alloc */
jsmntok_t *toks_alloc(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "toks_alloc called!\n"); abort(); }
Why this scored 18/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.