From ea4811b3b3086dcb62ad437f58dc7101e5d117a4 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 10 Jun 2020 12:37:15 +0200 Subject: [PATCH] conf: detect truncated lines If the buffer filled by fgets() is full, indicating it might not contain the whole line, abort with a fatal message. --- conf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/conf.c b/conf.c index 810989f..844150a 100644 --- 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);