From 3817a690c9708b1873264582d66a39bdf358e0cc Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2022 13:20:31 +0930 Subject: [PATCH] gossipd: actually validate gossip_store checksums at startup. We rewrite the file to compact it, but as a side effect we recalculate the checksums! Signed-off-by: Rusty Russell --- gossipd/gossip_store.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index 873be7f88..29d3bc110 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -175,6 +175,16 @@ static u32 gossip_store_compact_offline(struct routing_state *rstate) continue; } + /* Check checksum (upgrade would overwrite, so do it now) */ + if (be32_to_cpu(hdr.crc) + != crc32c(be32_to_cpu(hdr.timestamp), msg, msglen)) { + status_broken("gossip_store_compact_offline: checksum verification failed? %08x should be %08x", + be32_to_cpu(hdr.crc), + crc32c(be32_to_cpu(hdr.timestamp), msg + sizeof(hdr), msglen)); + tal_free(msg); + goto close_and_delete; + } + if (oldversion != version) { if (!upgrade_field(oldversion, rstate, &msg)) { tal_free(msg);