diff --git a/src/path/filepath/match.go b/src/path/filepath/match.go index 2adb0c74908..9fa68f578d0 100644 --- a/src/path/filepath/match.go +++ b/src/path/filepath/match.go @@ -250,6 +250,11 @@ func Glob(pattern string) (matches []string, err error) { return glob(dir, file, nil) } + // Prevent infinite recursion. See issue 15879. + if dir == pattern { + return nil, ErrBadPattern + } + var m []string m, err = Glob(dir) if err != nil { diff --git a/src/path/filepath/match_test.go b/src/path/filepath/match_test.go index 8dcfa5972e5..6b068c778e9 100644 --- a/src/path/filepath/match_test.go +++ b/src/path/filepath/match_test.go @@ -159,6 +159,12 @@ func TestGlobError(t *testing.T) { } } +func TestGlobUNC(t *testing.T) { + // Just make sure this runs without crashing for now. + // See issue 15879. + Glob(`\\?\C:\*`) +} + var globSymlinkTests = []struct { path, dest string brokenLink bool