]> granicus.if.org Git - curl/commitdiff
parsecfg: do not continue past a zero termination
authorDaniel Stenberg <daniel@haxx.se>
Thu, 16 Apr 2015 22:38:50 +0000 (00:38 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 17 Apr 2015 09:44:57 +0000 (11:44 +0200)
When a config file line ends without newline, the parsing function could
continue reading beyond that point in memory.

Reported-by: Hanno Böck
src/tool_parsecfg.c

index fabdbc20b6c580faccfed19cbceac3aed128121c..4c25ddbd511a1e7342fe594464e26786f9bab87b 100644 (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))
-          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);
+          }
         }
       }