[PATCH 2/4] worktree add: reject separator-only path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]




worktree_basename() extracts an empty basename from a path consisting
only of zero or more path separators. We can't use that as a worktree
name. Properly report such a path as invalid instead of triggering a
BUG that asks the user what just happened.
Original-patch-by: Matthias Aßhauer <mha1993@xxxxxxx>
Signed-off-by: René Scharfe <l.s.r@xxxxxx>
---
 builtin/worktree.c | 2 ++
 t/t2400-worktree-add.sh | 4 ++++
 2 files changed, 6 insertions(+)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index a770dd5ead..a53e815cc9 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -491,6 +491,8 @@ static int add_worktree(const char *path, const char *refname,
 
 	name = worktree_basename(path, &len);
 	strbuf_add(&sb, name, path + len - name);
+	if (!sb.len)
+		die(_("invalid path '%s'"), path);
 	sanitize_refname_component(sb.buf, &sb_name);
 	if (!sb_name.len)
 		BUG("How come '%s' becomes empty after sanitization?", sb.buf);
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index 87b926728a..280d2e2c07 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -46,6 +46,10 @@ test_expect_success '"add" refuses to checkout locked branch' '
 	test_path_is_missing .git/worktrees/zere
 '
 
+test_expect_success '"add" rejects an empty path' '
+	test_must_fail git worktree add "" HEAD
+'
+
 test_expect_success 'checking out paths not complaining about linked checkouts' '
 	(
 	cd existing_empty &&
-- 
2.55.0

[Index of Archives] [Linux Kernel Development] [Gcc Help] [IETF Annouce] [DCCP] [Netdev] [Networking] [Security] [V4L] [Bugtraq] [Yosemite] [MIPS Linux] [ARM Linux] [Linux Security] [Linux RAID] [Linux SCSI] [Fedora Users]

(追記) (追記ここまで)
Powered by Linux

AltStyle によって変換されたページ (->オリジナル) /