aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2015-04-17 00:38:50 +0200
committerDaniel Stenberg <daniel@haxx.se>2015-04-17 11:44:57 +0200
commit691a07dac6df0a827aa3f0b3e21000cdb362a7fb (patch)
treefbc5ff986ab03e85c0f10304819d5cfda480d49b
parent05e4137d313d928d8f5971a50452c683ef3b8205 (diff)
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
-rw-r--r--src/tool_parsecfg.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c
index fabdbc20b..4c25ddbd5 100644
--- a/src/tool_parsecfg.c
+++ b/src/tool_parsecfg.c
@@ -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))
- line++;
+ if(*line) {
+ *line = '\0'; /* zero terminate */
- 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);
+ /* 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);
+ }
}
}