From ae7faece88af1051583106061b2449ce36994c73 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 7 Jun 2018 17:31:36 +0300 Subject: [PATCH] Sanity validate ntp response --- timesource/timesource.go | 3 +++ timesource/timesource_test.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/timesource/timesource.go b/timesource/timesource.go index 2e951faba..8705818d8 100644 --- a/timesource/timesource.go +++ b/timesource/timesource.go @@ -73,6 +73,9 @@ func computeOffset(timeQuery ntpQuery, servers []string, allowedFailures int) (t response, err := timeQuery(server, ntp.QueryOptions{ Timeout: DefaultRPCTimeout, }) + if err == nil { + err = response.Validate() + } if err != nil { responses <- queryResponse{Error: err} return diff --git a/timesource/timesource_test.go b/timesource/timesource_test.go index 9b3744968..0c38851d8 100644 --- a/timesource/timesource_test.go +++ b/timesource/timesource_test.go @@ -39,7 +39,10 @@ func (tc *testCase) query(string, ntp.QueryOptions) (*ntp.Response, error) { tc.actualAttempts++ tc.mu.Unlock() }() - response := &ntp.Response{ClockOffset: tc.responses[tc.actualAttempts].Offset} + response := &ntp.Response{ + ClockOffset: tc.responses[tc.actualAttempts].Offset, + Stratum: 1, + } return response, tc.responses[tc.actualAttempts].Error }