From d4738e1259f97ee14687300ee01e6e6da4701bb4 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 17 May 2023 16:37:55 +0200 Subject: [PATCH] ntp: set minimum polltarget 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index 8ce9ed9..02394b8 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -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); }