From cacd64bf4a1fb5248f16c1fa5008a4beed568844 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 2 Jun 2025 10:53:47 +0200 Subject: [PATCH] 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") --- conf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/conf.c b/conf.c index cd3466b..a6bb3bf 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,