Skip to content

Commit

Permalink
connectd: better diagnostics on invalid gossip_store entries.
Browse files Browse the repository at this point in the history
Should help diagnose ElementsProject#5572
which hit the invalid csum on a >64MB entry, if it happens again.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Sep 13, 2022
1 parent 67b75b1 commit 3763c50
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions common/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ u8 *gossip_store_next(const tal_t *ctx,
size_t *off, size_t *end)
{
u8 *msg = NULL;
size_t initial_off = *off;

while (!msg) {
struct gossip_hdr hdr;
Expand Down Expand Up @@ -146,6 +147,14 @@ u8 *gossip_store_next(const tal_t *ctx,
continue;
}

/* Messages can be up to 64k, but we also have internal ones:
* 128k is plenty. */
if (msglen > 128 * 1024)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"gossip_store: oversize msg len %u at"
" offset %zu (was at %zu)",
msglen, *off, initial_off);

checksum = be32_to_cpu(hdr.crc);
msg = tal_arr(ctx, u8, msglen);
r = pread(*gossip_store_fd, msg, msglen, *off + r);
Expand All @@ -155,8 +164,8 @@ u8 *gossip_store_next(const tal_t *ctx,
if (checksum != crc32c(be32_to_cpu(hdr.timestamp), msg, msglen))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"gossip_store: bad checksum at offset %zu"
": %s",
*off, tal_hex(tmpctx, msg));
"(was at %zu): %s",
*off, initial_off, tal_hex(tmpctx, msg));

/* Definitely processing it now */
*off += sizeof(hdr) + msglen;
Expand Down

0 comments on commit 3763c50

Please sign in to comment.