Skip to content

Commit

Permalink
config: Permit config files to omit terminating newlines (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvaiya committed Mar 10, 2023
1 parent c525da3 commit 04c9e15
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down

0 comments on commit 04c9e15

Please sign in to comment.