From 97bb6c5a28822842beeb11d2492529ca33d9f9cd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 4 Jun 2018 13:55:25 +0930 Subject: [PATCH] gossipd: ensure incoming timestamps are reasonable. This is kind of orthogonal to the other changes, but makes sense: if we would instantly or never prune the message, don't accept it. Signed-off-by: Rusty Russell --- gossipd/routing.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gossipd/routing.c b/gossipd/routing.c index 0926736f9..83b53cf5a 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1071,6 +1071,28 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, } } + /* BOLT #7: + * + * - if the `timestamp` is unreasonably far in the future: + * - MAY discard the `channel_announcement`. + */ + if (timestamp > time_now().ts.tv_sec + rstate->prune_timeout) { + status_debug("Received channel_update for %s with far time %u", + type_to_string(tmpctx, struct short_channel_id, + &short_channel_id), + timestamp); + return NULL; + } + + /* Note: we can consider old timestamps a case of "instant prune" too */ + if (timestamp < time_now().ts.tv_sec - rstate->prune_timeout) { + status_debug("Received channel_update for %s with old time %u", + type_to_string(tmpctx, struct short_channel_id, + &short_channel_id), + timestamp); + return NULL; + } + c = &chan->half[direction]; if (is_halfchan_defined(c) && timestamp <= c->last_timestamp) {