Skip to content

Commit 8b145bb

Browse files
committed
Merge branch 'en/fast-import-path-sanitize' into next
"git fast-import" learned to reject paths with ".." and "." as their components to avoid creating invalid tree objects. * en/fast-import-path-sanitize: fast-import: disallow "." and ".." path components
2 parents 7bb66a1 + 4a2790a commit 8b145bb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

builtin/fast-import.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,8 @@ static int tree_content_set(
14671467
root->tree = t = grow_tree_content(t, t->entry_count);
14681468
e = new_tree_entry();
14691469
e->name = to_atom(p, n);
1470+
if (is_dot_or_dotdot(e->name->str_dat))
1471+
die("path %s contains invalid component", p);
14701472
e->versions[0].mode = 0;
14711473
oidclr(&e->versions[0].oid, the_repository->hash_algo);
14721474
t->entries[t->entry_count++] = e;

t/t9300-fast-import.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,26 @@ test_expect_success 'B: fail on invalid committer (5)' '
521521
test_must_fail git fast-import <input
522522
'
523523

524+
test_expect_success 'B: fail on invalid file path' '
525+
cat >input <<-INPUT_END &&
526+
blob
527+
mark :1
528+
data <<EOF
529+
File contents
530+
EOF
531+
532+
commit refs/heads/badpath
533+
committer Name <email> $GIT_COMMITTER_DATE
534+
data <<COMMIT
535+
Commit Message
536+
COMMIT
537+
M 100644 :1 ../invalid-path
538+
INPUT_END
539+
540+
test_when_finished "git update-ref -d refs/heads/badpath" &&
541+
test_must_fail git fast-import <input
542+
'
543+
524544
###
525545
### series C
526546
###

0 commit comments

Comments
 (0)