From 04c9e15d70fe1019dc5a38359540270caf86cfcb Mon Sep 17 00:00:00 2001 From: Raheman Vaiya Date: Fri, 10 Mar 2023 14:47:58 -0500 Subject: [PATCH] config: Permit config files to omit terminating newlines (#414) --- src/config.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 9cfdaa6..1b619ec 100644 --- a/src/config.c +++ b/src/config.c @@ -110,7 +110,7 @@ static char *read_file(const char *path) const char include_prefix[] = "include "; static char buf[MAX_FILE_SZ]; - char line[MAX_LINE_LEN]; + char line[MAX_LINE_LEN+1]; int sz = 0; FILE *fh = fopen(path, "r"); @@ -123,8 +123,12 @@ static char *read_file(const char *path) int len = strlen(line); if (line[len-1] != '\n') { - err("maximum line length exceed (%d)", MAX_LINE_LEN); - goto fail; + if (len >= MAX_LINE_LEN) { + err("maximum line length exceed (%d)", MAX_LINE_LEN); + goto fail; + } else { + line[len++] = '\n'; + } } if ((len+sz) > MAX_FILE_SZ) {