git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fast-import: disallow "." and ".." path components
@ 2024-11-25 17:58 Elijah Newren via GitGitGadget
  2024-11-25 18:15 ` Eric Sunshine
  2024-11-25 19:00 ` [PATCH v2] " Elijah Newren via GitGitGadget
  0 siblings, 2 replies; 14+ messages in thread
From: Elijah Newren via GitGitGadget @ 2024-11-25 17:58 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

If a user specified e.g.
   M 100644 :1 ../some-file
then fast-import previously would happily create a git history where
there is a tree in the top-level directory named "..", and with a file
inside that directory named "some-file".  The top-level ".." directory
causes problems.  While git checkout will die with errors and fsck will
report hasDotdot problems, the user is going to have problems trying to
remove the problematic file.  Simply avoid creating this bad history in
the first place.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
    fast-import: disallow "." and ".." path components

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1831%2Fnewren%2Fdisallow-dotdot-fast-import-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1831/newren/disallow-dotdot-fast-import-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1831

 builtin/fast-import.c  |  3 +++
 t/t9300-fast-import.sh | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 76d5c20f141..e0e0ca3657a 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1466,6 +1466,9 @@ static int tree_content_set(
 		root->tree = t = grow_tree_content(t, t->entry_count);
 	e = new_tree_entry();
 	e->name = to_atom(p, n);
+	if (!strcmp(e->name->str_dat, ".") || !strcmp(e->name->str_dat, "..")) {
+		die("path %s contains invalid component", p);
+	}
 	e->versions[0].mode = 0;
 	oidclr(&e->versions[0].oid, the_repository->hash_algo);
 	t->entries[t->entry_count++] = e;
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 6224f54d4d2..caf3dc003a0 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -522,6 +522,26 @@ test_expect_success 'B: fail on invalid committer (5)' '
 	test_must_fail git fast-import <input
 '
 
+test_expect_success 'B: fail on invalid file path' '
+	cat >input <<-INPUT_END &&
+	blob
+	mark :1
+	data <<EOF
+	File contents
+	EOF
+
+	commit refs/heads/badpath
+	committer Name <email> $GIT_COMMITTER_DATE
+	data <<COMMIT
+	Commit Message
+	COMMIT
+	M 100644 :1 ../invalid-path
+	INPUT_END
+
+	test_when_finished "git update-ref -d refs/heads/badpath" &&
+	test_must_fail git fast-import <input
+'
+
 ###
 ### series C
 ###

base-commit: 04eaff62f286226f501dd21f069e0e257aee11a6
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-11-28  9:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-25 17:58 [PATCH] fast-import: disallow "." and ".." path components Elijah Newren via GitGitGadget
2024-11-25 18:15 ` Eric Sunshine
2024-11-25 18:24   ` Elijah Newren
2024-11-25 19:00 ` [PATCH v2] " Elijah Newren via GitGitGadget
2024-11-26  6:57   ` Patrick Steinhardt
2024-11-27 14:24     ` Jeff King
2024-11-27 23:07       ` Junio C Hamano
2024-11-27  8:28   ` Kristoffer Haugsbakk
2024-11-27 13:23     ` Re* " Junio C Hamano
2024-11-27 19:41       ` Eric Sunshine
2024-11-28  0:36       ` [PATCH v2] CodingGuidelines: a handful of error message guidelines Junio C Hamano
2024-11-28  7:57         ` Eric Sunshine
2024-11-28  9:28           ` Junio C Hamano
2024-11-28  9:51             ` Eric Sunshine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).