From 05c37e58c1d289f24fe01001ed12f2d0988efc72 Mon Sep 17 00:00:00 2001 From: Benny Ng Date: Wed, 12 Oct 2016 20:55:38 +0000 Subject: [PATCH] lib/osutil: Prevent infinite Glob recursion (fixes #3577) Skip-check: authors GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3665 --- lib/osutil/glob_windows.go | 2 +- lib/osutil/glob_windows_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 lib/osutil/glob_windows_test.go diff --git a/lib/osutil/glob_windows.go b/lib/osutil/glob_windows.go index 5952f18a5..e521330c0 100644 --- a/lib/osutil/glob_windows.go +++ b/lib/osutil/glob_windows.go @@ -26,7 +26,7 @@ func Glob(pattern string) (matches []string, err error) { return []string{pattern}, nil } - dir, file := filepath.Split(pattern) + dir, file := filepath.Split(filepath.Clean(pattern)) switch dir { case "": dir = "." diff --git a/lib/osutil/glob_windows_test.go b/lib/osutil/glob_windows_test.go new file mode 100644 index 000000000..9d552bfd5 --- /dev/null +++ b/lib/osutil/glob_windows_test.go @@ -0,0 +1,29 @@ +// Copyright (C) 2014 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at http://mozilla.org/MPL/2.0/. + +// +build windows + +package osutil_test + +import ( + "testing" + + "github.com/syncthing/syncthing/lib/osutil" +) + +func TestGlob(t *testing.T) { + testcases := []string{ + `C:\*`, + `\\?\C:\*`, + `\\?\C:\Users`, + `\\?\\\?\C:\Users`, + } + for _, tc := range testcases { + if _, err := osutil.Glob(tc); err != nil { + t.Fatalf("pattern %s failed: %v", tc, err) + } + } +}