diff --git a/include/common/defaults.h b/include/common/defaults.h index 5b18767ca5..1a69f40d9b 100644 --- a/include/common/defaults.h +++ b/include/common/defaults.h @@ -43,8 +43,13 @@ #define REQURI_LEN 1024 #define CAPTURE_LEN 64 +// maximum line size when parsing config +#ifndef LINESIZE +#define LINESIZE 2048 +#endif + // max # args on a configuration line -#define MAX_LINE_ARGS 40 +#define MAX_LINE_ARGS 64 // max # of added headers per request #define MAX_NEWHDR 10 diff --git a/src/cfgparse.c b/src/cfgparse.c index 6fcf09fde3..e347cff8fb 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2305,13 +2305,9 @@ int cfg_parse_listen(const char *file, int linenum, char **args) */ int readcfgfile(const char *file) { - char thisline[256]; - char *line; + char thisline[LINESIZE]; FILE *f; int linenum = 0; - char *end; - char *args[MAX_LINE_ARGS + 1]; - int arg; int cfgerr = 0; int confsect = CFG_NONE; @@ -2323,11 +2319,25 @@ int readcfgfile(const char *file) init_default_instance(); - while (fgets(line = thisline, sizeof(thisline), f) != NULL) { + while (fgets(thisline, sizeof(thisline), f) != NULL) { + int arg; + char *end; + char *args[MAX_LINE_ARGS + 1]; + char *line = thisline; + linenum++; end = line + strlen(line); + if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') { + /* Check if we reached the limit and the last char is not \n. + * Watch out for the last line without the terminating '\n'! + */ + Alert("parsing [%s:%d]: line too long, limit: %d.\n", + file, linenum, sizeof(thisline)-1); + return -1; + } + /* skip leading spaces */ while (isspace((unsigned char)*line)) line++; @@ -2385,7 +2395,7 @@ int readcfgfile(const char *file) } else if (isspace((unsigned char)*line)) { /* a non-escaped space is an argument separator */ - *line++ = 0; + *line++ = '\0'; while (isspace((unsigned char)*line)) line++; args[++arg] = line;