From 0fd8a6492e1e233aa03dc5246b044a58a01cb309 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 25 Jul 2022 13:33:59 +0930 Subject: [PATCH] lightningd: fix fatal() log message in log. The one to stderr is fine, the log one gets corrupted, like so: ``` 2022-07-24T07:20:08.6250702Z lightningd-2 2022-07-24T06:49:19.494Z **BROKEN** lightningd: Plugin '????UH??SH??8H?}?H?u?H?U?H?M?H?M?H?E?H?????' returned an invalid response to the db_write hook: (F???U ``` Signed-off-by: Rusty Russell --- lightningd/log.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lightningd/log.c b/lightningd/log.c index dd44636b1..ff7f1602e 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -840,14 +840,20 @@ void log_backtrace_exit(void) void fatal_vfmt(const char *fmt, va_list ap) { + va_list ap2; + + /* You are not allowed to re-use va_lists, so make a copy. */ + va_copy(ap2, ap); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); if (!crashlog) exit(1); - logv(crashlog, LOG_BROKEN, NULL, true, fmt, ap); + logv(crashlog, LOG_BROKEN, NULL, true, fmt, ap2); abort(); + /* va_copy() must be matched with va_end(), even if unreachable. */ + va_end(ap2); } void fatal(const char *fmt, ...)