From e34ec8da2d8acb0da1e9ff2ee2df258c508b5c4c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 10 Jan 2018 15:16:54 +1030 Subject: [PATCH] peer_failed: use towire_errorfmtv() which doesn't add nul terminator. This code was actually wrong. Signed-off-by: Rusty Russell --- closingd/Makefile | 3 ++- common/peer_failed.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/closingd/Makefile b/closingd/Makefile index 2cb6786b7..5e64e9f14 100644 --- a/closingd/Makefile +++ b/closingd/Makefile @@ -58,7 +58,8 @@ CLOSINGD_COMMON_OBJS := \ common/subdaemon.o \ common/type_to_string.o \ common/utils.o \ - common/version.o + common/version.o \ + common/wire_error.o closingd/gen_closing_wire.h: $(WIRE_GEN) closingd/closing_wire.csv $(WIRE_GEN) --header $@ closing_wire_type < closingd/closing_wire.csv > $@ diff --git a/common/peer_failed.c b/common/peer_failed.c index 5ee61bf6c..e1facd0f0 100644 --- a/common/peer_failed.c +++ b/common/peer_failed.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -31,9 +32,10 @@ void peer_failed(int peer_fd, struct crypto_state *cs, va_start(ap, fmt); errmsg = tal_vfmt(NULL, fmt, ap); va_end(ap); - /* Make sure it's correct length for error. */ - tal_resize(&errmsg, strlen(errmsg)+1); - msg = towire_error(errmsg, channel_id, (const u8 *)errmsg); + + va_start(ap, fmt); + msg = towire_errorfmtv(errmsg, channel_id, fmt, ap); + va_end(ap); /* This is only best-effort; don't block. */ io_fd_block(peer_fd, false);