File: conf%3A_fix_sourcedir_reloading_to_not_multiply_sources.patch

package info (click to toggle)
chrony 4.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,760 kB
  • sloc: ansic: 37,943; sh: 5,436; yacc: 862; makefile: 227
file content (56 lines) | stat: -rw-r--r-- 2,438 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
From cacd64bf4a1fb5248f16c1fa5008a4beed568844 Mon Sep 17 00:00:00 2001
From: Miroslav Lichvar <mlichvar@redhat.com>
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 <MichaelR42@runbox.com>
Fixes: 916ed70c4a81 ("conf: save source status in sourcedir reload")
---
 conf.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Index: chrony/conf.c
===================================================================
--- chrony.orig/conf.c
+++ chrony/conf.c
@@ -1742,8 +1742,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)
@@ -1782,13 +1782,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,