Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast-import: disallow "." and ".." path components #1831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions builtin/fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions t/t9300-fast-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
###
Expand Down
Loading