Skip to content

Commit 6aed567

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a02ea57 commit 6aed567

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ static int check_submodule_url(const char *url)
10861086
if (looks_like_command_line_option(url))
10871087
return -1;
10881088

1089-
if (submodule_url_is_relative(url)) {
1089+
if (submodule_url_is_relative(url) || starts_with(url, "git://")) {
10901090
char *decoded;
10911091
const char *next;
10921092
int has_nl;

t/t7416-submodule-dash-url.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,19 @@ test_expect_success 'fsck rejects embedded newline in relative url' '
201201
grep gitmodulesUrl err
202202
'
203203

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+
204219
test_done

0 commit comments

Comments
 (0)