Git fork

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

+117 -4
+6
builtin/fast-import.c
··· 13 13 #include "delta.h" 14 14 #include "pack.h" 15 15 #include "path.h" 16 + #include "read-cache-ll.h" 16 17 #include "refs.h" 17 18 #include "csum-file.h" 18 19 #include "quote.h" ··· 2425 2426 tree_content_replace(&b->branch_tree, &oid, mode, NULL); 2426 2427 return; 2427 2428 } 2429 + 2430 + if (!verify_path(path.buf, mode)) 2431 + die("invalid path '%s'", path.buf); 2428 2432 tree_content_set(&b->branch_tree, path.buf, &oid, mode, NULL); 2429 2433 } 2430 2434 ··· 2462 2466 leaf.tree); 2463 2467 return; 2464 2468 } 2469 + if (!verify_path(dest.buf, leaf.versions[1].mode)) 2470 + die("invalid path '%s'", dest.buf); 2465 2471 tree_content_set(&b->branch_tree, dest.buf, 2466 2472 &leaf.versions[1].oid, 2467 2473 leaf.versions[1].mode,
+110 -3
t/t9300-fast-import.sh
··· 521 521 test_must_fail git fast-import <input 522 522 ' 523 523 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 + 524 631 ### 525 632 ### series C 526 633 ### ··· 945 1052 :100644 100644 M ba 946 1053 EXPECT_END 947 1054 948 - git fast-import <input && 1055 + git -c core.protectNTFS=false fast-import <input && 949 1056 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output && 950 1057 cut -d" " -f1,2,5 output >actual && 951 1058 test_cmp expect actual ··· 3096 3203 test_expect_success "S: paths at EOL with $test must work" ' 3097 3204 test_when_finished "git branch -D S-path-eol" && 3098 3205 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 && 3100 3207 blob 3101 3208 mark :401 3102 3209 data <<BLOB ··· 3205 3312 test_expect_success "S: paths before space with $test must work" ' 3206 3313 test_when_finished "git branch -D S-path-space" && 3207 3314 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 && 3209 3316 blob 3210 3317 mark :401 3211 3318 data <<BLOB
+1 -1
t/t9350-fast-export.sh
··· 631 631 git rev-list HEAD >expect && 632 632 git init result && 633 633 cd result && 634 - git fast-import <../export.out && 634 + git -c core.protectNTFS=false fast-import <../export.out && 635 635 git rev-list HEAD >actual && 636 636 test_cmp ../expect actual 637 637 )