aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortim775 <52185+tim775@users.noreply.github.com>2024-03-06 12:03:56 -0500
committertim775 <52185+tim775@users.noreply.github.com>2024-03-06 12:03:56 -0500
commit384dbf730bc337ff66a2705af707d12a515eca9e (patch)
treecee04e7a2e7a5083b06d25c0081b35d490f75544
parent8d007039aba42c77964cdcb14dd8b86ccabb3469 (diff)
downloadgo-git-384dbf730bc337ff66a2705af707d12a515eca9e.tar.gz
git: worktree, Don't panic on empty or root path when checking if it is valid
I didn't dig into the specific case that was triggering this, but we did have a panic in our production system.
-rw-r--r--worktree.go4
-rw-r--r--worktree_test.go2
2 files changed, 6 insertions, 0 deletions
diff --git a/worktree.go b/worktree.go
index 4dfe036..ab11d42 100644
--- a/worktree.go
+++ b/worktree.go
@@ -428,6 +428,10 @@ var worktreeDeny = map[string]struct{}{
func validPath(paths ...string) error {
for _, p := range paths {
parts := strings.FieldsFunc(p, func(r rune) bool { return (r == '\\' || r == '/') })
+ if len(parts) == 0 {
+ return fmt.Errorf("invalid path: %q", p)
+ }
+
if _, denied := worktreeDeny[strings.ToLower(parts[0])]; denied {
return fmt.Errorf("invalid path prefix: %q", p)
}
diff --git a/worktree_test.go b/worktree_test.go
index 2c3c592..668c30a 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -2957,6 +2957,8 @@ func TestValidPath(t *testing.T) {
{"git~1", true},
{"a/../b", true},
{"a\\..\\b", true},
+ {"/", true},
+ {"", true},
{".gitmodules", false},
{".gitignore", false},
{"a..b", false},