]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: detect truncated lines
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Jun 2020 10:37:15 +0000 (12:37 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Jun 2020 11:56:43 +0000 (13:56 +0200)
If the buffer filled by fgets() is full, indicating it might not contain
the whole line, abort with a fatal message.

conf.c

diff --git a/conf.c b/conf.c
index 810989f93bbbdd53e932e37c2818fa3e2e4d1b1c..844150a772cde906f602b29aa36f2b7d4af3307a 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -433,7 +433,7 @@ void
 CNF_ReadFile(const char *filename)
 {
   FILE *in;
-  char line[MAX_LINE_LENGTH];
+  char line[MAX_LINE_LENGTH + 1];
   int i;
 
   include_level++;
@@ -463,6 +463,10 @@ CNF_ParseLine(const char *filename, int number, char *line)
   processed_file = filename;
   line_number = number;
 
+  /* Detect truncated line */
+  if (strlen(line) >= MAX_LINE_LENGTH)
+    other_parse_error("String too long");
+
   /* Remove extra white-space and comments */
   CPS_NormalizeLine(line);