3 test_description='check handling of .. in submodule names
5 Exercise the name-checking function on a variety of names, and then give a
6 real-world setup that confirms we catch this in practice.
9 . "$TEST_DIRECTORY"/lib-pack.sh
11 test_expect_success 'check names' '
12 cat >expect <<-\EOF &&
17 git submodule--helper check-name >actual <<-\EOF &&
32 test_cmp expect actual
35 test_expect_success 'create innocent subrepo' '
37 git -C innocent commit --allow-empty -m foo
40 test_expect_success 'submodule add refuses invalid names' '
42 git submodule add --name ../../modules/evil "$PWD/innocent" evil
45 test_expect_success 'add evil submodule' '
46 git submodule add "$PWD/innocent" evil &&
49 cp -r .git/modules/evil modules &&
50 write_script modules/evil/hooks/post-checkout <<-\EOF &&
51 echo >&2 "RUNNING POST CHECKOUT"
54 git config -f .gitmodules submodule.evil.update checkout &&
55 git config -f .gitmodules --rename-section \
56 submodule.evil submodule.../../modules/evil &&
61 # This step seems like it shouldn't be necessary, since the payload is
62 # contained entirely in the evil submodule. But due to the vagaries of the
63 # submodule code, checking out the evil module will fail unless ".git/modules"
64 # exists. Adding another submodule (with a name that sorts before "evil") is an
65 # easy way to make sure this is the case in the victim clone.
66 test_expect_success 'add other submodule' '
67 git submodule add "$PWD/innocent" another-module &&
68 git add another-module &&
69 git commit -am another
72 test_expect_success 'clone evil superproject' '
73 git clone --recurse-submodules . victim >output 2>&1 &&
74 ! grep "RUNNING POST CHECKOUT" output
77 test_expect_success 'fsck detects evil superproject' '
78 test_must_fail git fsck
81 test_expect_success 'transfer.fsckObjects detects evil superproject (unpack)' '
83 git init --bare dst.git &&
84 git -C dst.git config transfer.fsckObjects true &&
85 test_must_fail git push dst.git HEAD
88 test_expect_success 'transfer.fsckObjects detects evil superproject (index)' '
90 git init --bare dst.git &&
91 git -C dst.git config transfer.fsckObjects true &&
92 git -C dst.git config transfer.unpackLimit 1 &&
93 test_must_fail git push dst.git HEAD
96 # Normally our packs contain commits followed by trees followed by blobs. This
97 # reverses the order, which requires backtracking to find the context of a
98 # blob. We'll start with a fresh gitmodules-only tree to make it simpler.
99 test_expect_success 'create oddly ordered pack' '
100 git checkout --orphan odd &&
101 git rm -rf --cached . &&
102 git add .gitmodules &&
106 pack_obj $(git rev-parse HEAD:.gitmodules) &&
107 pack_obj $(git rev-parse HEAD^{tree}) &&
108 pack_obj $(git rev-parse HEAD)
110 pack_trailer odd.pack
113 test_expect_success 'transfer.fsckObjects handles odd pack (unpack)' '
115 git init --bare dst.git &&
116 test_must_fail git -C dst.git unpack-objects --strict <odd.pack
119 test_expect_success 'transfer.fsckObjects handles odd pack (index)' '
121 git init --bare dst.git &&
122 test_must_fail git -C dst.git index-pack --strict --stdin <odd.pack
125 test_expect_success 'fsck detects symlinked .gitmodules file' '
130 # Make the tree directly to avoid index restrictions.
132 # Because symlinks store the target as a blob, choose
133 # a pathname that could be parsed as a .gitmodules file
134 # to trick naive non-symlink-aware checking.
135 tricky="[foo]bar=true" &&
136 content=$(git hash-object -w ../.gitmodules) &&
137 target=$(printf "$tricky" | git hash-object -w --stdin) &&
140 printf "100644 blob $content\t$tricky\n" &&
141 printf "120000 blob $target\t.gitmodules\n"
144 commit=$(git commit-tree $tree) &&
146 # Check not only that we fail, but that it is due to the
147 # symlink detector; this grep string comes from the config
148 # variable name and will not be translated.
149 test_must_fail git fsck 2>output &&
150 grep gitmodulesSymlink output