From 5944524d01e6f02dd1c80cc09757b941d8b4eba5 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 20 Mar 2018 14:53:59 +0100 Subject: [PATCH] gossip: Avoid reading gossip messages that we just wrote Signed-off-by: Christian Decker --- gossipd/gossip_store.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index 55e80f835..b80d22540 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -58,9 +58,17 @@ const u8 *gossip_store_read_next(const tal_t *ctx, struct gossip_store *gs) beint16_t belen; u16 msglen; u8 *msg; - if (!read_all(gs->read_fd, &belen, sizeof(belen))) + + /* Did we already reach the end of the gossip_store? */ + if (gs->read_fd == -1) return NULL; + /* Can we read one message? */ + if (!read_all(gs->read_fd, &belen, sizeof(belen))) { + gs->read_fd = -1; + return NULL; + } + msglen = be16_to_cpu(belen); msg = tal_arr(ctx, u8, msglen);