From 6af04d10bf4ff90cd9bee35ff96e9e73195da73f Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Tue, 13 Sep 2022 18:39:59 -0500 Subject: [PATCH] gossip_store: fix offset error The gossip_store version byte was unaccounted for in the initial traversal of gossip_store_end. This lead to an offset and a bogus message length field. As a result, an early portion of the gossip_store could have been skipped, potentially leading to gossip propagation issues downstream. Fixes #5572 #5565 Changelog-fixed: proper gossip_store operation may resolve some previous gossip propagation issues --- common/gossip_store.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/gossip_store.c b/common/gossip_store.c index 2f3f329a2d2e..9cb05951693b 100644 --- a/common/gossip_store.c +++ b/common/gossip_store.c @@ -199,8 +199,8 @@ size_t find_gossip_store_end(int gossip_store_fd, size_t off) } buf; int r; - while ((r = read(gossip_store_fd, &buf, - sizeof(buf.hdr) + sizeof(buf.type))) + while ((r = pread(gossip_store_fd, &buf, + sizeof(buf.hdr) + sizeof(buf.type), off)) == sizeof(buf.hdr) + sizeof(buf.type)) { u32 msglen = be32_to_cpu(buf.hdr.len) & GOSSIP_STORE_LEN_MASK; @@ -209,7 +209,6 @@ size_t find_gossip_store_end(int gossip_store_fd, size_t off) break; off += sizeof(buf.hdr) + msglen; - lseek(gossip_store_fd, off, SEEK_SET); } return off; }