From: Miroslav Lichvar Date: Mon, 2 Jun 2025 08:53:47 +0000 (+0200) Subject: conf: fix sourcedir reloading to not multiply sources X-Git-Tag: 4.7~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cacd64bf4a1fb5248f16c1fa5008a4beed568844;p=thirdparty%2Fchrony.git conf: fix sourcedir reloading to not multiply sources The sourcedir reload triggered by the chronyc "reload sources" command incorrectly assumed that NSR_AddSourceByName() can return only the NSR_Success status when a source is added. It ignored the NSR_UnresolvedName status returned for a source whose name needs to be resolved after the call (i.e. not specified with an IP address) and added the source again, effectively multiplying it if the name can be resolved to a different IP address. Fix the code to check for the NSR_UnresolvedName status to correctly determine whether the source was already added before and should not be added again. Reported-by: MichaelR Fixes: 916ed70c4a81 ("conf: save source status in sourcedir reload") --- diff --git a/conf.c b/conf.c index cd3466b8..a6bb3bf4 100644 --- a/conf.c +++ b/conf.c @@ -1872,8 +1872,8 @@ reload_source_dirs(void) NTP_Source *prev_sources, *new_sources, *source; unsigned int i, j, prev_size, new_size, unresolved; char buf[MAX_LINE_LENGTH]; + int d, pass, was_added; NSR_Status s; - int d, pass; /* Ignore reload command before adding configured sources */ if (!conf_ntp_sources_added) @@ -1912,13 +1912,16 @@ reload_source_dirs(void) else d = i < prev_size ? -1 : 1; + was_added = d <= 0 && (prev_sources[i].status == NSR_Success || + prev_sources[i].status == NSR_UnresolvedName); + /* Remove missing sources before adding others to avoid conflicts */ - if (pass == 0 && d < 0 && prev_sources[i].status == NSR_Success) { + if (pass == 0 && d < 0 && was_added) { NSR_RemoveSourcesById(prev_sources[i].conf_id); } /* Add new sources and sources that could not be added before */ - if (pass == 1 && (d > 0 || (d == 0 && prev_sources[i].status != NSR_Success))) { + if (pass == 1 && (d > 0 || (d == 0 && !was_added))) { source = &new_sources[j]; s = NSR_AddSourceByName(source->params.name, source->params.family, source->params.port, source->pool, source->type, &source->params.params,