]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: set minimum polltarget
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 17 May 2023 14:37:55 +0000 (16:37 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 18 May 2023 08:46:46 +0000 (10:46 +0200)
The polltarget value is used in a floating-point division in the
calculation of the poll adjustment. Set 1 as the minimum accepted
polltarget value to avoid working with infinite values.

ntp_core.c

index 8ce9ed9beabfcecdfcf0d07fea175bbc1845298c..02394b84f14194a5536d370756301fca566ca231 100644 (file)
@@ -647,7 +647,7 @@ NCR_CreateInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
   result->auto_burst = params->burst;
   result->auto_offline = params->auto_offline;
   result->copy = params->copy && result->mode == MODE_CLIENT;
-  result->poll_target = params->poll_target;
+  result->poll_target = MAX(1, params->poll_target);
   result->ext_field_flags = params->ext_fields;
 
   if (params->nts) {
@@ -2900,7 +2900,7 @@ NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum)
 void
 NCR_ModifyPolltarget(NCR_Instance inst, int new_poll_target)
 {
-  inst->poll_target = new_poll_target;
+  inst->poll_target = MAX(1, new_poll_target);
   LOG(LOGS_INFO, "Source %s new polltarget %d",
       UTI_IPToString(&inst->remote_addr.ip_addr), new_poll_target);
 }