]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: fix marking of non-preferred selectable sources
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 8 Jun 2015 09:48:29 +0000 (11:48 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 8 Jun 2015 09:54:43 +0000 (11:54 +0200)
When reducing the list of selectable sources to sources with the prefer
option, sources before the first preferred source were left with the
SRC_OK status, which triggered an assertion failure in the next
selection.

sources.c

index 8817649f0e453a92b6be418247fb6c06daa779fc..1ba2a740745d7164343868a70b2d2b171e1dd704 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -872,16 +872,18 @@ SRC_SelectSource(SRC_Instance updated_inst)
 
   /* If there are any sources with prefer option, reduce the list again
      only to the preferred sources */
-  for (i = j = 0; i < n_sel_sources; i++) {
+  for (i = 0; i < n_sel_sources; i++) {
     if (sources[sel_sources[i]]->sel_option == SRC_SelectPrefer)
-      sel_sources[j++] = sel_sources[i];
+      break;
   }
-
-  if (j > 0) {
-    for (i = 0; i < n_sel_sources; i++) {
+  if (i < n_sel_sources) {
+    for (i = j = 0; i < n_sel_sources; i++) {
       if (sources[sel_sources[i]]->sel_option != SRC_SelectPrefer)
         sources[sel_sources[i]]->status = SRC_NONPREFERRED;
+      else
+        sel_sources[j++] = sel_sources[i];
     }
+    assert(j > 0);
     n_sel_sources = j;
     sel_prefer = 1;
   } else {