aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2024-11-25 19:00:48 +0000
committerJunio C Hamano <gitster@pobox.com>2024-11-26 10:30:04 +0900
commit4a2790a257b314ab59f6f2e25f3d7ca120219922 (patch)
tree1853f38fc72b4a75d04ae6cf7ef5d31cf4941da2
parentGit 2.47.1 (diff)
downloadgit-4a2790a257b314ab59f6f2e25f3d7ca120219922.tar.gz
git-4a2790a257b314ab59f6f2e25f3d7ca120219922.zip
fast-import: disallow "." and ".." path components
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/fast-import.c2
-rwxr-xr-xt/t9300-fast-import.sh20
2 files changed, 22 insertions, 0 deletions
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1e7ab67f6e..3e7ec1f119 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1468,6 +1468,8 @@ 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 (is_dot_or_dotdot(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 3b3c371740..5a5127fffa 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
###