From 90a5ba043c809329c62ba19c2b24c95b67b10311 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 21 Dec 2017 14:20:47 +1030 Subject: [PATCH] htlc_out: initialize hout->key.id, in case we destroy it before setting. We set hout->key.id when channeld tells us what it is, but if channeld dies before that we free the hout, and our destructor logs it: Valgrind error file: valgrind-errors.20312 ==20312== Use of uninitialised value of size 8 ==20312== at 0x53ABC9B: _itoa_word (_itoa.c:179) ==20312== by 0x53B041F: vfprintf (vfprintf.c:1642) ==20312== by 0x53B17D5: buffered_vfprintf (vfprintf.c:2330) ==20312== by 0x53AEAA5: vfprintf (vfprintf.c:1301) ==20312== by 0x53B7D63: fprintf (fprintf.c:32) ==20312== by 0x128BAC: hout_subd_died (peer_htlcs.c:316) ==20312== by 0x16D8E0: notify (tal.c:240) ==20312== by 0x16DD95: del_tree (tal.c:400) ==20312== by 0x16DDE7: del_tree (tal.c:410) ==20312== by 0x16DDE7: del_tree (tal.c:410) ==20312== by 0x16E1B4: tal_free (tal.c:509) ==20312== by 0x162B5C: io_close (io.c:443) ==20312== by 0x12D563: sd_msg_read (subd.c:508) ==20312== by 0x161EA5: next_plan (io.c:59) ==20312== by 0x1629A2: do_plan (io.c:387) ==20312== by 0x1629E0: io_ready (io.c:397) ==20312== by 0x164319: io_loop (poll.c:305) ==20312== by 0x118E21: main (lightningd.c:334) Signed-off-by: Rusty Russell --- lightningd/htlc_end.c | 1 + lightningd/htlc_end.h | 2 ++ lightningd/peer_htlcs.c | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lightningd/htlc_end.c b/lightningd/htlc_end.c index c6d17709b..acf9d180e 100644 --- a/lightningd/htlc_end.c +++ b/lightningd/htlc_end.c @@ -150,6 +150,7 @@ struct htlc_out *new_htlc_out(const tal_t *ctx, hout->dbid = 0; hout->key.peer = peer; + hout->key.id = HTLC_INVALID_ID; hout->msatoshi = msatoshi; hout->cltv_expiry = cltv_expiry; hout->payment_hash = *payment_hash; diff --git a/lightningd/htlc_end.h b/lightningd/htlc_end.h index 9e41375df..140300c7b 100644 --- a/lightningd/htlc_end.h +++ b/lightningd/htlc_end.h @@ -13,6 +13,8 @@ struct htlc_key { u64 id; }; +#define HTLC_INVALID_ID (-1ULL) + /* Incoming HTLC */ struct htlc_in { /* The database primary key for this htlc. Must be 0 until it diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index ab15745b2..0d98685d6 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -352,7 +352,8 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds, return; } - if (find_htlc_out(&subd->ld->htlcs_out, hout->key.peer, hout->key.id)) { + if (find_htlc_out(&subd->ld->htlcs_out, hout->key.peer, hout->key.id) + || hout->key.id == HTLC_INVALID_ID) { peer_internal_error(subd->peer, "Bad offer_htlc_reply HTLC id %"PRIu64 " is a duplicate",