From 486f13bbec488424037a24e7d58a9e1c2f91d19f Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Wed, 27 Nov 2024 09:24:17 -0800 Subject: [PATCH] fast-import: disallow more path components Instead of just disallowing '.' and '..', make use of verify_path() to ensure that fast-import will disallow anything we wouldn't allow into the index, such as anything under .git/, .gitmodules as a symlink, or a dos drive prefix on Windows. Signed-off-by: Elijah Newren --- builtin/fast-import.c | 5 +-- t/t9300-fast-import.sh | 82 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 995ef76f9d6c6a..1e7452dd64d0ab 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -13,6 +13,7 @@ #include "delta.h" #include "pack.h" #include "path.h" +#include "read-cache-ll.h" #include "refs.h" #include "csum-file.h" #include "quote.h" @@ -1411,6 +1412,8 @@ static int tree_content_set( die("Empty path component found in input"); if (!*slash1 && !S_ISDIR(mode) && subtree) die("Non-directories cannot have subtrees"); + if (!verify_path(p, mode)) + die("invalid path '%s'", p); if (!root->tree) load_tree(root); @@ -1466,8 +1469,6 @@ 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 caf3dc003a028b..e8e8a191d9dcd6 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -522,7 +522,7 @@ test_expect_success 'B: fail on invalid committer (5)' ' test_must_fail git fast-import input <<-INPUT_END && blob mark :1 @@ -542,6 +542,86 @@ test_expect_success 'B: fail on invalid file path' ' test_must_fail git fast-import input <<-INPUT_END && + blob + mark :1 + data < $GIT_COMMITTER_DATE + data <input <<-INPUT_END && + blob + mark :1 + data < $GIT_COMMITTER_DATE + data <input <<-INPUT_END && + blob + mark :1 + data < $GIT_COMMITTER_DATE + data <input <<-INPUT_END && + blob + mark :1 + data < $GIT_COMMITTER_DATE + data <