From f447e39d2d9af7e0885a5586aee1fb0c153d6d0c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 23 Mar 2022 10:01:14 +1030 Subject: [PATCH] offers: neater response on malformed invoice. Signed-off-by: Rusty Russell --- plugins/offers_inv_hook.c | 15 +++++++++------ plugins/offers_invreq_hook.c | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/plugins/offers_inv_hook.c b/plugins/offers_inv_hook.c index 0e3128ae6..bfeb5b87f 100644 --- a/plugins/offers_inv_hook.c +++ b/plugins/offers_inv_hook.c @@ -28,12 +28,15 @@ fail_inv_level(struct command *cmd, struct tlv_invoice_error *err; u8 *errdata; - full_fmt = tal_fmt(tmpctx, "Failed invoice %s", - invoice_encode(tmpctx, inv->inv)); - if (inv->inv->offer_id) - tal_append_fmt(&full_fmt, " for offer %s", - type_to_string(tmpctx, struct sha256, - inv->inv->offer_id)); + full_fmt = tal_fmt(tmpctx, "Failed invoice"); + if (inv->inv) { + tal_append_fmt(&full_fmt, " %s", + invoice_encode(tmpctx, inv->inv)); + if (inv->inv->offer_id) + tal_append_fmt(&full_fmt, " for offer %s", + type_to_string(tmpctx, struct sha256, + inv->inv->offer_id)); + } tal_append_fmt(&full_fmt, ": %s", fmt); msg = tal_vfmt(tmpctx, full_fmt, ap); diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index 1092c7c06..f4b131ff6 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -38,12 +38,15 @@ fail_invreq_level(struct command *cmd, struct tlv_invoice_error *err; u8 *errdata; - full_fmt = tal_fmt(tmpctx, "Failed invoice_request %s", - invrequest_encode(tmpctx, invreq->invreq)); - if (invreq->invreq->offer_id) - tal_append_fmt(&full_fmt, " for offer %s", - type_to_string(tmpctx, struct sha256, - invreq->invreq->offer_id)); + full_fmt = tal_fmt(tmpctx, "Failed invoice_request"); + if (invreq->invreq) { + tal_append_fmt(&full_fmt, " %s", + invrequest_encode(tmpctx, invreq->invreq)); + if (invreq->invreq->offer_id) + tal_append_fmt(&full_fmt, " for offer %s", + type_to_string(tmpctx, struct sha256, + invreq->invreq->offer_id)); + } tal_append_fmt(&full_fmt, ": %s", fmt); msg = tal_vfmt(tmpctx, full_fmt, ap);