]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck: reject .gitmodules git:// urls with newlines
authorJeff King <peff@peff.net>
Thu, 7 Jan 2021 09:44:17 +0000 (04:44 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Jan 2021 22:25:44 +0000 (14:25 -0800)
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>
fsck.c
t/t7416-submodule-dash-url.sh

diff --git a/fsck.c b/fsck.c
index c4a9fe624a9d4c316530c947dcf25e01e6c21432..a8870a54b6ad75f0d55f0fa16d69aa6ff3350866 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1086,7 +1086,7 @@ static int check_submodule_url(const char *url)
        if (looks_like_command_line_option(url))
                return -1;
 
-       if (submodule_url_is_relative(url)) {
+       if (submodule_url_is_relative(url) || starts_with(url, "git://")) {
                char *decoded;
                const char *next;
                int has_nl;
index eec96e0ba9e371e9603bd47ad5e13f0e547d7b5a..d21dc8b009f6d0d8e75368d01a984ac350155ba3 100755 (executable)
@@ -201,4 +201,19 @@ test_expect_success 'fsck rejects embedded newline in relative url' '
        grep gitmodulesUrl err
 '
 
+test_expect_success 'fsck rejects embedded newline in git url' '
+       git checkout --orphan git-newline &&
+       cat >.gitmodules <<-\EOF &&
+       [submodule "foo"]
+       url = "git://example.com:1234/repo%0a.git"
+       EOF
+       git add .gitmodules &&
+       git commit -m "git url with newline" &&
+       test_when_finished "rm -rf dst" &&
+       git init --bare dst &&
+       git -C dst config transfer.fsckObjects true &&
+       test_must_fail git push dst HEAD 2>err &&
+       grep gitmodulesUrl err
+'
+
 test_done