mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
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:
parent
fe50f1a158
commit
60c07b259e
@ -461,7 +461,18 @@ func parseIgnoreFile(fs fs.Filesystem, fd io.Reader, currentFile string, cd Chan
|
|||||||
line = filepath.ToSlash(line)
|
line = filepath.ToSlash(line)
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(line, "#include"):
|
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)
|
includeFile := filepath.Join(filepath.Dir(currentFile), includeRel)
|
||||||
var includePatterns []Pattern
|
var includePatterns []Pattern
|
||||||
if includePatterns, err = loadParseIncludeFile(fs, includeFile, cd, linesSeen); err == nil {
|
if includePatterns, err = loadParseIncludeFile(fs, includeFile, cd, linesSeen); err == nil {
|
||||||
|
@ -1079,3 +1079,22 @@ func TestSpecialChars(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPartialIncludeLine(t *testing.T) {
|
||||||
|
// Loading a partial #include line (no file mentioned) should error but not crash.
|
||||||
|
|
||||||
|
pats := New(fs.NewFilesystem(fs.FilesystemTypeBasic, "."), WithCache(true))
|
||||||
|
cases := []string{
|
||||||
|
"#include",
|
||||||
|
"#include\n",
|
||||||
|
"#include ",
|
||||||
|
"#include \n",
|
||||||
|
"#include \n\n\n",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
if err := pats.Parse(bytes.NewBufferString(tc), ".stignore"); err == nil {
|
||||||
|
t.Fatal("should error out")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user