From 6a48ed9e826efed1ea53b18a8308f97c2d5bbe34 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 18 Sep 2022 09:51:50 +0930 Subject: [PATCH] gossmap: fail to get capacity of locally-added chans (don't crash!). Signed-off-by: Rusty Russell --- common/gossmap.c | 4 ++++ common/gossmap.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/gossmap.c b/common/gossmap.c index 17c5cbe88..7262f2259 100644 --- a/common/gossmap.c +++ b/common/gossmap.c @@ -967,6 +967,10 @@ bool gossmap_chan_get_capacity(const struct gossmap *map, size_t off; u16 type; + /* Fail for local channels */ + if (c->cann_off >= map->map_size) + return false; + /* For private, we need to go back WIRE_GOSSIP_STORE_PRIVATE_CHANNEL, * which is 8 (satoshis) + 2 (len) */ if (c->private) { diff --git a/common/gossmap.h b/common/gossmap.h index 728dc8385..1f06dcb51 100644 --- a/common/gossmap.h +++ b/common/gossmap.h @@ -117,7 +117,7 @@ static inline bool gossmap_chan_set(const struct gossmap_chan *chan, int dir) return chan->cupdate_off[dir] != 0; } -/* Return capacity if it's known (fails only on race condition) */ +/* Return capacity if it's known (fails only on race condition, or a local mod) */ bool gossmap_chan_get_capacity(const struct gossmap *map, const struct gossmap_chan *c, struct amount_sat *amount);