]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: make sure new configuration IDs are unused
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 29 Jul 2024 12:33:14 +0000 (14:33 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 30 Jul 2024 10:11:09 +0000 (12:11 +0200)
The configuration IDs assigned to individual sources (used when they
don't have a resolved IP address) and pools of sources are 32-bit. The
ID could overflow if some sources were very frequently removed and added
again. Two unrelated sources could end up with the same ID, causing some
operations to unexpectedly impact only one or both sources.

Make sure the ID is currently unused before assigning it to a new source.

ntp_sources.c

index 64d9a8b46323c138639ca855522a29255142ead7..29c99acfe10d56632f9a5720f8bb96d9eb1596ef 100644 (file)
@@ -770,8 +770,19 @@ static int get_unused_pool_id(void)
 static uint32_t
 get_next_conf_id(uint32_t *conf_id)
 {
+  SourceRecord *record;
+  unsigned int i;
+
+again:
   last_conf_id++;
 
+  /* Make sure the ID is not already used (after 32-bit wraparound) */
+  for (i = 0; i < ARR_GetSize(records); i++) {
+    record = get_record(i);
+    if (record->remote_addr && record->conf_id == last_conf_id)
+      goto again;
+  }
+
   if (conf_id)
     *conf_id = last_conf_id;