From f4d92813a0e536fd0786ac7b3a0bf247a1b2adc2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 19 May 2017 20:33:39 +0930 Subject: [PATCH] lightningd: handle bad failure message. We used to core dump if unwrap_onionreply() returned NULL! Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 4d5ca1389..22e1e09b6 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1187,10 +1187,15 @@ static int peer_failed_htlc(struct peer *peer, const u8 *msg) shared_secrets[i] = hend->path_secrets[i]; } reply = unwrap_onionreply(msg, shared_secrets, numhops, reason); - failcode = fromwire_peektype(reply->msg); - log_info(peer->log, "htlc %"PRIu64" failed with code 0x%04x (%s)", - id, failcode, onion_type_name(failcode)); - + if (!reply) { + log_info(peer->log, "htlc %"PRIu64" failed with bad reply (%s)", + id, tal_hex(msg, msg)); + failcode = WIRE_PERMANENT_NODE_FAILURE; + } else { + failcode = fromwire_peektype(reply->msg); + log_info(peer->log, "htlc %"PRIu64" failed with code 0x%04x (%s)", + id, failcode, onion_type_name(failcode)); + } payment_failed(peer->ld, hend, NULL, failcode); } tal_free(hend);