Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

Commit 8139164

Browse files
committed
gossipd: disallow far future (+1 day) or far past (2 weeks) timestamps.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 7686068 commit 8139164

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

gossipd/routing.c

+34
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ static void destroy_routing_state(struct routing_state *rstate)
195195
local_chan_map_clear(&rstate->local_chan_map);
196196
}
197197

198+
/* We don't check this when loading from the gossip_store: that would break
199+
* our canned tests, and usually old gossip is better than no gossip */
200+
static bool timestamp_reasonable(struct routing_state *rstate, u32 timestamp)
201+
{
202+
u64 now = gossip_time_now(rstate).ts.tv_sec;
203+
204+
/* More than one day ahead? */
205+
if (timestamp > now + 24*60*60)
206+
return false;
207+
/* More than 2 weeks behind? */
208+
if (timestamp < now - rstate->prune_timeout)
209+
return false;
210+
return true;
211+
}
212+
198213
#if DEVELOPER
199214
static void memleak_help_routing_tables(struct htable *memtable,
200215
struct routing_state *rstate)
@@ -1949,6 +1964,17 @@ bool routing_add_channel_update(struct routing_state *rstate,
19491964
}
19501965
}
19511966

1967+
/* Check timestamp is sane (unless from store). */
1968+
if (!index && !timestamp_reasonable(rstate, timestamp)) {
1969+
status_debug("Ignoring update timestamp %u for %s/%u",
1970+
timestamp,
1971+
type_to_string(tmpctx,
1972+
struct short_channel_id,
1973+
&short_channel_id),
1974+
direction);
1975+
return false;
1976+
}
1977+
19521978
/* OK, we're going to accept this, so create chan if doesn't exist */
19531979
if (uc) {
19541980
assert(!chan);
@@ -2267,6 +2293,14 @@ bool routing_add_node_announcement(struct routing_state *rstate,
22672293
status_debug("Received node_announcement for node %s",
22682294
type_to_string(tmpctx, struct node_id, &node_id));
22692295

2296+
/* Check timestamp is sane (unless from gossip_store). */
2297+
if (!index && !timestamp_reasonable(rstate, timestamp)) {
2298+
status_debug("Ignoring node_announcement timestamp %u for %s",
2299+
timestamp,
2300+
type_to_string(tmpctx, struct node_id, &node_id));
2301+
return false;
2302+
}
2303+
22702304
node = get_node(rstate, &node_id);
22712305

22722306
if (node == NULL || !node_has_broadcastable_channels(node)) {

0 commit comments

Comments
 (0)