]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: set maximum allowed polling interval
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Apr 2015 12:01:25 +0000 (14:01 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Apr 2015 12:06:53 +0000 (14:06 +0200)
To have an upper bound don't allow polling interval be larger than 24
(194 days).

ntp_core.c

index 2e8e5c6331b1d327c2ea1b71df6fe1a93c50520e..2eace49a739c10e55d2254569c4b36d8882e3e91 100644 (file)
@@ -217,8 +217,9 @@ static ARR_Instance broadcasts;
 /* Invalid stratum number */
 #define NTP_INVALID_STRATUM 0
 
-/* Minimum allowed poll interval */
+/* Minimum and maximum allowed poll interval */
 #define MIN_POLL 0
+#define MAX_POLL 24
 
 /* Kiss-o'-Death codes */
 #define KOD_RATE 0x52415445UL /* RATE */
@@ -445,9 +446,13 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar
   result->minpoll = params->minpoll;
   if (result->minpoll < MIN_POLL)
     result->minpoll = SRC_DEFAULT_MINPOLL;
+  else if (result->minpoll > MAX_POLL)
+    result->minpoll = MAX_POLL;
   result->maxpoll = params->maxpoll;
   if (result->maxpoll < MIN_POLL)
     result->maxpoll = SRC_DEFAULT_MAXPOLL;
+  else if (result->maxpoll > MAX_POLL)
+    result->maxpoll = MAX_POLL;
   if (result->maxpoll < result->minpoll)
     result->maxpoll = result->minpoll;
 
@@ -1734,7 +1739,7 @@ NCR_TakeSourceOffline(NCR_Instance inst)
 void
 NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll)
 {
-  if (new_minpoll < MIN_POLL)
+  if (new_minpoll < MIN_POLL || new_minpoll > MAX_POLL)
     return;
   inst->minpoll = new_minpoll;
   LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new minpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_minpoll);
@@ -1747,7 +1752,7 @@ NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll)
 void
 NCR_ModifyMaxpoll(NCR_Instance inst, int new_maxpoll)
 {
-  if (new_maxpoll < MIN_POLL)
+  if (new_maxpoll < MIN_POLL || new_maxpoll > MAX_POLL)
     return;
   inst->maxpoll = new_maxpoll;
   LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new maxpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_maxpoll);