mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-06 11:55:06 -05:00
conf: detect infinite inclusion
Don't allow more than 10 nested inclusions using the include or confdirs directive to cleanly handle a misconfiguration with a circular inclusion.
This commit is contained in:
9
conf.c
9
conf.c
@@ -46,6 +46,7 @@
|
|||||||
|
|
||||||
#define MAX_LINE_LENGTH 2048
|
#define MAX_LINE_LENGTH 2048
|
||||||
#define MAX_CONF_DIRS 10
|
#define MAX_CONF_DIRS 10
|
||||||
|
#define MAX_INCLUDE_LEVEL 10
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Forward prototypes */
|
/* Forward prototypes */
|
||||||
@@ -291,6 +292,8 @@ static int line_number;
|
|||||||
static const char *processed_file;
|
static const char *processed_file;
|
||||||
static const char *processed_command;
|
static const char *processed_command;
|
||||||
|
|
||||||
|
static int include_level = 0;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -433,6 +436,10 @@ CNF_ReadFile(const char *filename)
|
|||||||
char line[MAX_LINE_LENGTH];
|
char line[MAX_LINE_LENGTH];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
include_level++;
|
||||||
|
if (include_level > MAX_INCLUDE_LEVEL)
|
||||||
|
LOG_FATAL("Maximum include level reached");
|
||||||
|
|
||||||
in = UTI_OpenFile(NULL, filename, NULL, 'R', 0);
|
in = UTI_OpenFile(NULL, filename, NULL, 'R', 0);
|
||||||
|
|
||||||
for (i = 1; fgets(line, sizeof(line), in); i++) {
|
for (i = 1; fgets(line, sizeof(line), in); i++) {
|
||||||
@@ -440,6 +447,8 @@ CNF_ReadFile(const char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
|
include_level--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
Reference in New Issue
Block a user