parsecfg: do not continue past a zero termination

When a config file line ends without newline, the parsing function could
continue reading beyond that point in memory.

Reported-by: Hanno Böck
This commit is contained in:
Daniel Stenberg 2015-04-17 00:38:50 +02:00
parent 05e4137d31
commit 691a07dac6
1 changed files with 18 additions and 15 deletions

View File

@ -187,24 +187,27 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
param = line; /* parameter starts here */
while(*line && !ISSPACE(*line))
line++;
*line = '\0'; /* zero terminate */
/* to detect mistakes better, see if there's data following */
line++;
/* pass all spaces */
while(*line && ISSPACE(*line))
if(*line) {
*line = '\0'; /* zero terminate */
/* to detect mistakes better, see if there's data following */
line++;
/* pass all spaces */
while(*line && ISSPACE(*line))
line++;
switch(*line) {
case '\0':
case '\r':
case '\n':
case '#': /* comment */
break;
default:
warnf(operation->global, "%s:%d: warning: '%s' uses unquoted white "
"space in the line that may cause side-effects!\n",
filename, lineno, option);
switch(*line) {
case '\0':
case '\r':
case '\n':
case '#': /* comment */
break;
default:
warnf(operation->global, "%s:%d: warning: '%s' uses unquoted "
"white space in the line that may cause side-effects!\n",
filename, lineno, option);
}
}
}