Skip to content

Commit e56c283

Browse files
committed
Merge branch 'en/fast-import-verify-path'
"git fast-import" learned to reject paths with ".." and "." as their components to avoid creating invalid tree objects. * en/fast-import-verify-path: t9300: test verification of renamed paths fast-import: disallow more path components fast-import: disallow "." and ".." path components
2 parents 90bf05e + 8cb4c6e commit e56c283

File tree

3 files changed

+117
-4
lines changed

3 files changed

+117
-4
lines changed

builtin/fast-import.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "delta.h"
1414
#include "pack.h"
1515
#include "path.h"
16+
#include "read-cache-ll.h"
1617
#include "refs.h"
1718
#include "csum-file.h"
1819
#include "quote.h"
@@ -2425,6 +2426,9 @@ static void file_change_m(const char *p, struct branch *b)
24252426
tree_content_replace(&b->branch_tree, &oid, mode, NULL);
24262427
return;
24272428
}
2429+
2430+
if (!verify_path(path.buf, mode))
2431+
die("invalid path '%s'", path.buf);
24282432
tree_content_set(&b->branch_tree, path.buf, &oid, mode, NULL);
24292433
}
24302434

@@ -2462,6 +2466,8 @@ static void file_change_cr(const char *p, struct branch *b, int rename)
24622466
leaf.tree);
24632467
return;
24642468
}
2469+
if (!verify_path(dest.buf, leaf.versions[1].mode))
2470+
die("invalid path '%s'", dest.buf);
24652471
tree_content_set(&b->branch_tree, dest.buf,
24662472
&leaf.versions[1].oid,
24672473
leaf.versions[1].mode,

t/t9300-fast-import.sh

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,113 @@ 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 of ..' '
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+
544+
test_expect_success 'B: fail on invalid file path of .' '
545+
cat >input <<-INPUT_END &&
546+
blob
547+
mark :1
548+
data <<EOF
549+
File contents
550+
EOF
551+
552+
commit refs/heads/badpath
553+
committer Name <email> $GIT_COMMITTER_DATE
554+
data <<COMMIT
555+
Good path
556+
COMMIT
557+
M 100644 :1 ok-path
558+
559+
commit refs/heads/badpath
560+
committer Name <email> $GIT_COMMITTER_DATE
561+
data <<COMMIT
562+
Bad path
563+
COMMIT
564+
R ok-path ./invalid-path
565+
INPUT_END
566+
567+
test_when_finished "git update-ref -d refs/heads/badpath" &&
568+
test_must_fail git fast-import <input
569+
'
570+
571+
test_expect_success WINDOWS 'B: fail on invalid file path of C:' '
572+
cat >input <<-INPUT_END &&
573+
blob
574+
mark :1
575+
data <<EOF
576+
File contents
577+
EOF
578+
579+
commit refs/heads/badpath
580+
committer Name <email> $GIT_COMMITTER_DATE
581+
data <<COMMIT
582+
Commit Message
583+
COMMIT
584+
M 100644 :1 C:/invalid-path
585+
INPUT_END
586+
587+
test_when_finished "git update-ref -d refs/heads/badpath" &&
588+
test_must_fail git fast-import <input
589+
'
590+
591+
test_expect_success 'B: fail on invalid file path of .git' '
592+
cat >input <<-INPUT_END &&
593+
blob
594+
mark :1
595+
data <<EOF
596+
File contents
597+
EOF
598+
599+
commit refs/heads/badpath
600+
committer Name <email> $GIT_COMMITTER_DATE
601+
data <<COMMIT
602+
Commit Message
603+
COMMIT
604+
M 100644 :1 .git/invalid-path
605+
INPUT_END
606+
607+
test_when_finished "git update-ref -d refs/heads/badpath" &&
608+
test_must_fail git fast-import <input
609+
'
610+
611+
test_expect_success 'B: fail on invalid file path of .gitmodules' '
612+
cat >input <<-INPUT_END &&
613+
blob
614+
mark :1
615+
data <<EOF
616+
File contents
617+
EOF
618+
619+
commit refs/heads/badpath
620+
committer Name <email> $GIT_COMMITTER_DATE
621+
data <<COMMIT
622+
Commit Message
623+
COMMIT
624+
M 120000 :1 .gitmodules
625+
INPUT_END
626+
627+
test_when_finished "git update-ref -d refs/heads/badpath" &&
628+
test_must_fail git fast-import <input
629+
'
630+
524631
###
525632
### series C
526633
###
@@ -945,7 +1052,7 @@ test_expect_success 'L: verify internal tree sorting' '
9451052
:100644 100644 M ba
9461053
EXPECT_END
9471054
948-
git fast-import <input &&
1055+
git -c core.protectNTFS=false fast-import <input &&
9491056
GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
9501057
cut -d" " -f1,2,5 output >actual &&
9511058
test_cmp expect actual
@@ -3096,7 +3203,7 @@ test_path_eol_success () {
30963203
test_expect_success "S: paths at EOL with $test must work" '
30973204
test_when_finished "git branch -D S-path-eol" &&
30983205
3099-
git fast-import --export-marks=marks.out <<-EOF >out 2>err &&
3206+
git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF >out 2>err &&
31003207
blob
31013208
mark :401
31023209
data <<BLOB
@@ -3205,7 +3312,7 @@ test_path_space_success () {
32053312
test_expect_success "S: paths before space with $test must work" '
32063313
test_when_finished "git branch -D S-path-space" &&
32073314
3208-
git fast-import --export-marks=marks.out <<-EOF 2>err &&
3315+
git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF 2>err &&
32093316
blob
32103317
mark :401
32113318
data <<BLOB

t/t9350-fast-export.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ test_expect_success 'fast-export quotes pathnames' '
631631
git rev-list HEAD >expect &&
632632
git init result &&
633633
cd result &&
634-
git fast-import <../export.out &&
634+
git -c core.protectNTFS=false fast-import <../export.out &&
635635
git rev-list HEAD >actual &&
636636
test_cmp ../expect actual
637637
)

0 commit comments

Comments
 (0)