short_channel_id: make mk_short_channel_id return a failure.

We had a bug 0ba547ee10 caused by
short_channel_id overflow.  If we'd caught this, we'd have terminated
the peer instead of crashing, so add appropriate checks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-01-21 11:27:43 +10:30
committed by Christian Decker
parent d69680934e
commit 018a3f1d58
5 changed files with 44 additions and 22 deletions

View File

@@ -537,9 +537,15 @@ static enum watch_result funding_lockin_cb(struct lightningd *ld,
loc = wallet_transaction_locate(tmpctx, ld->wallet, txid);
channel->scid = tal(channel, struct short_channel_id);
mk_short_channel_id(channel->scid,
loc->blkheight, loc->index,
channel->funding_outnum);
if (!mk_short_channel_id(channel->scid,
loc->blkheight, loc->index,
channel->funding_outnum)) {
channel_fail_permanent(channel, "Invalid funding scid %u:%u:%u",
loc->blkheight, loc->index,
channel->funding_outnum);
return DELETE_WATCH;
}
/* We've added scid, update */
wallet_channel_save(ld->wallet, channel);
}