lib/ignore: Don't crash in partial #include line (ref #5985) (#5986)

If the line is just "#include" with nothing following it we would crash
with an index out of bounds error. Now it's a little more careful.
This commit is contained in:
Jakob Borg
2019-08-30 10:36:31 +01:00
committed by Simon Frei
parent fe50f1a158
commit 60c07b259e
2 changed files with 31 additions and 1 deletions

View File

@@ -461,7 +461,18 @@ func parseIgnoreFile(fs fs.Filesystem, fd io.Reader, currentFile string, cd Chan
line = filepath.ToSlash(line)
switch {
case strings.HasPrefix(line, "#include"):
includeRel := strings.TrimSpace(line[len("#include "):])
fields := strings.SplitN(line, " ", 2)
if len(fields) != 2 {
err = fmt.Errorf("failed to parse #include line: no file?")
break
}
includeRel := strings.TrimSpace(fields[1])
if includeRel == "" {
err = fmt.Errorf("failed to parse #include line: no file?")
break
}
includeFile := filepath.Join(filepath.Dir(currentFile), includeRel)
var includePatterns []Pattern
if includePatterns, err = loadParseIncludeFile(fs, includeFile, cd, linesSeen); err == nil {