From 75a93ec32f8ddb132f99d04622a948d8ed6c0cbf Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 8 May 2020 13:32:13 +0930 Subject: [PATCH] lightningd: EXPERIMENTAL_FEATURES: fix crash caused by test_sendonionmessage Commit b0c9059602ea2f84ba6507372919b5140e56e302 broke the case where next_node_id is NULL: [libsecp256k1] illegal argument: pubkey != NULL lightning_channeld: FATAL SIGNAL 6 (version 13d9c27) 0x55b4cd261b64 send_backtrace common/daemon.c:39 0x55b4cd261c0e crashdump common/daemon.c:52 0x7fc60307746f ??? ???:0 0x7fc6030773eb ??? ???:0 0x7fc603056898 ??? ???:0 0x55b4cd2c7cee ??? ???:0 0x55b4cd2d74d4 ??? ???:0 0x55b4cd26ac62 node_id_from_pubkey common/node_id.c:12 0x55b4cd24e194 handle_onion_message channeld/channeld.c:1890 0x55b4cd24e697 peer_in channeld/channeld.c:2001 0x55b4cd2521f4 main channeld/channeld.c:3419 0x7fc6030581e2 ??? ???:0 0x55b4cd24881d ??? ???:0 0xffffffffffffffff ??? ???:0 Signed-off-by: Rusty Russell --- channeld/channeld.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index a4229c9d0..10e603d7a 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1879,7 +1879,7 @@ static void handle_onion_message(struct peer *peer, const u8 *msg) path))); } else { struct pubkey *next_blinding; - struct node_id next_node; + struct node_id *next_node; /* This *MUST* have instructions on where to go next. */ if (!om->next_short_channel_id && !om->next_node_id) { @@ -1888,7 +1888,6 @@ static void handle_onion_message(struct peer *peer, const u8 *msg) return; } - node_id_from_pubkey(&next_node, om->next_node_id); if (blinding_ss) { /* E(i-1) = H(E(i) || ss(i)) * E(i) */ struct sha256 h; @@ -1898,10 +1897,16 @@ static void handle_onion_message(struct peer *peer, const u8 *msg) } else next_blinding = NULL; + if (om->next_node_id) { + next_node = tal(tmpctx, struct node_id); + node_id_from_pubkey(next_node, om->next_node_id); + } else + next_node = NULL; + wire_sync_write(MASTER_FD, take(towire_got_onionmsg_forward(NULL, om->next_short_channel_id, - &next_node, + next_node, next_blinding, serialize_onionpacket(tmpctx, rs->next)))); }