]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: detect infinite inclusion
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 11 May 2020 10:20:06 +0000 (12:20 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 May 2020 13:37:38 +0000 (15:37 +0200)
Don't allow more than 10 nested inclusions using the include or
confdirs directive to cleanly handle a misconfiguration with a circular
inclusion.

conf.c

diff --git a/conf.c b/conf.c
index bfab31c2e415a4aee75d07ca5cc349ae03ee2c33..247492222394da317d5d6155895c247c81c5bc55 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -46,6 +46,7 @@
 
 #define MAX_LINE_LENGTH 2048
 #define MAX_CONF_DIRS 10
+#define MAX_INCLUDE_LEVEL 10
 
 /* ================================================== */
 /* Forward prototypes */
@@ -291,6 +292,8 @@ static int line_number;
 static const char *processed_file;
 static const char *processed_command;
 
+static int include_level = 0;
+
 /* ================================================== */
 
 static void
@@ -433,6 +436,10 @@ CNF_ReadFile(const char *filename)
   char line[MAX_LINE_LENGTH];
   int i;
 
+  include_level++;
+  if (include_level > MAX_INCLUDE_LEVEL)
+    LOG_FATAL("Maximum include level reached");
+
   in = UTI_OpenFile(NULL, filename, NULL, 'R', 0);
 
   for (i = 1; fgets(line, sizeof(line), in); i++) {
@@ -440,6 +447,8 @@ CNF_ReadFile(const char *filename)
   }
 
   fclose(in);
+
+  include_level--;
 }
 
 /* ================================================== */