]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: require sourcedir files to be terminated by newline
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 15 Apr 2021 07:43:01 +0000 (09:43 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 15 Apr 2021 13:17:13 +0000 (15:17 +0200)
When reading a *.sources file require that each line is termined by the
newline character to avoid processing an unfinished line, e.g. due to an
unexpected call of the reload command when the file is being written in
place.

conf.c
doc/chrony.conf.adoc

diff --git a/conf.c b/conf.c
index 3567252f241329d6b66c1a50b2032a2bf8a6551d..1f3506159042226bed9b70f99c2b02e29b14e73c 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -1694,8 +1694,9 @@ load_source_file(const char *filename)
     return;
 
   while (fgets(line, sizeof (line), f)) {
-    if (strlen(line) >= MAX_LINE_LENGTH)
-      continue;
+    /* Require lines to be terminated */
+    if (line[0] == '\0' || line[strlen(line) - 1] != '\n')
+      break;
 
     CPS_NormalizeLine(line);
     if (line[0] == '\0')
index ff95cccf8bb6f957d00e8ed5b0f5ce58bda25050..117b2213718eda35bbf11c1b485fff32f02f67e0 100644 (file)
@@ -2310,7 +2310,8 @@ confdir @SYSCONFDIR@/chrony.d
 [[sourcedir]]*sourcedir* _directory_...::
 The *sourcedir* directive is identical to the *confdir* directive, except the
 configuration files have the _.sources_ suffix, they can only specify NTP
-sources (i.e. use the *server*, *pool*, and *peer* directive), and can be
+sources (i.e. the *server*, *pool*, and *peer* directives), they are expected
+to have all lines terminated by the newline character, and they can be
 reloaded by the <<chronyc.adoc#reload,*reload sources*>> command in
 *chronyc*. It is particularly useful with dynamic sources like NTP servers
 received from a DHCP server, which can be written to a file specific to the