Skip to content

Commit d26429b

Browse files
endothermicdevrustyrussell
authored andcommitted
gossipd: don't fail on gossip deletion
Reported in #6270, there was an attempt to delete gossip overrunning the end of the gossip_store. This logs the gossip type that was attempted to be deleted and avoids an immediate crash (tombstones would be fine to skip over at least.) Changelog-None
1 parent d9fe79c commit d26429b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

gossipd/gossip_store.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,15 +598,27 @@ static u32 delete_by_index(struct gossip_store *gs, u32 index, int type)
598598
/* Should never try to overwrite version */
599599
assert(index);
600600

601-
#if DEVELOPER
602-
const u8 *msg = gossip_store_get(tmpctx, gs, index);
603-
assert(fromwire_peektype(msg) == type);
604-
#endif
601+
/* FIXME: debugging a gs->len overrun issue reported in #6270 */
602+
if (pread(gs->fd, &hdr, sizeof(hdr), index) != sizeof(hdr)) {
603+
status_broken("gossip_store overrun during delete @%u type: %i"
604+
" gs->len: %"PRIu64, index, type, gs->len);
605+
return index;
606+
}
607+
if (index + sizeof(struct gossip_hdr) +
608+
be16_to_cpu(hdr.belen) > gs->len) {
609+
status_broken("gossip_store overrun during delete @%u type: %i"
610+
" gs->len: %"PRIu64, index, type, gs->len);
611+
return index;
612+
}
605613

606-
if (pread(gs->fd, &hdr, sizeof(hdr), index) != sizeof(hdr))
607-
status_failed(STATUS_FAIL_INTERNAL_ERROR,
608-
"Failed reading flags & len to delete @%u: %s",
609-
index, strerror(errno));
614+
const u8 *msg = gossip_store_get(tmpctx, gs, index);
615+
if(fromwire_peektype(msg) != type) {
616+
status_broken("asked to delete type %i @%u but store contains "
617+
"%i (gs->len=%"PRIu64"): %s",
618+
type, index, fromwire_peektype(msg),
619+
gs->len, tal_hex(tmpctx, msg));
620+
return index;
621+
}
610622

611623
assert((be16_to_cpu(hdr.beflags) & GOSSIP_STORE_DELETED_BIT) == 0);
612624
hdr.beflags |= cpu_to_be16(GOSSIP_STORE_DELETED_BIT);

0 commit comments

Comments
 (0)