fsck: reject .gitmodules git:// urls with newlines
The previous commit taught the clone/fetch client side to reject a git:// URL with a newline in it. Let's also catch these when fscking a .gitmodules file, which will give an earlier warning. Note that it would be simpler to just complain about newline in _any_ URL, but an earlier tightening for http/ftp made sure we kept allowing newlines for unknown protocols (and this is covered in the tests). So we'll stick to that precedent. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 7, 2021 at 04:44 UTC
6aed56736b882f94c81293d1646d27d10241349c
2 files changed
+16
-1
fsck.c
+1
-1
@@ -1086,7 +1086,7 @@ static int check_submodule_url(const char *url)
1086
if (looks_like_command_line_option(url))
1087
return -1;
1088
1089
- if (submodule_url_is_relative(url)) {
1089
+ if (submodule_url_is_relative(url) || starts_with(url, "git://")) {
1090
char *decoded;
1091
const char *next;
1092
int has_nl;
t/t7416-submodule-dash-url.sh
+15
@@ -201,4 +201,19 @@ test_expect_success 'fsck rejects embedded newline in relative url' '
201
grep gitmodulesUrl err
202
'
203
204
+test_expect_success 'fsck rejects embedded newline in git url' '
205
+ git checkout --orphan git-newline &&
206
+ cat >.gitmodules <<-\EOF &&
207
+ [submodule "foo"]
208
+ url = "git://example.com:1234/repo%0a.git"
209
+ EOF
210
+ git add .gitmodules &&
211
+ git commit -m "git url with newline" &&
212
+ test_when_finished "rm -rf dst" &&
213
+ git init --bare dst &&
214
+ git -C dst config transfer.fsckObjects true &&
215
+ test_must_fail git push dst HEAD 2>err &&
216
+ grep gitmodulesUrl err
217
+'
218
+
219
test_done