Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connectd: better diagnostics on invalid gossip_store entries. #5573

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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