]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/forbid-lf-in-git-url' into maint
authorJunio C Hamano <gitster@pobox.com>
Sat, 6 Feb 2021 00:31:27 +0000 (16:31 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 6 Feb 2021 00:31:27 +0000 (16:31 -0800)
Newline characters in the host and path part of git:// URL are
now forbidden.

* jk/forbid-lf-in-git-url:
  fsck: reject .gitmodules git:// urls with newlines
  git_connect_git(): forbid newlines in host and path

connect.c
fsck.c
t/t5570-git-daemon.sh
t/t7416-submodule-dash-url.sh

index 8b8f56cf6d230b23c46bb980755cb6d1fc3684ef..9c97fee43031056dff2beb2a8fe9ed882e476c2d 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -1160,6 +1160,8 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
                target_host = xstrdup(hostandport);
 
        transport_check_allowed("git");
+       if (strchr(target_host, '\n') || strchr(path, '\n'))
+               die(_("newline is forbidden in git:// hosts and repo paths"));
 
        /*
         * These underlying connection commands die() if they
diff --git a/fsck.c b/fsck.c
index f82e2fe9e302fed2e9ebf44c0323628cb94576f0..5e282b3b6b25d514d2e82bdd6b29c9c17da580a5 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1082,7 +1082,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 8f69a7854fb3108e1301f4b90961b3f6a1dc9e98..0fbb194810764f654903528b335afe328c64f5f0 100755 (executable)
@@ -103,6 +103,11 @@ test_expect_success 'fetch notices corrupt idx' '
        )
 '
 
+test_expect_success 'client refuses to ask for repo with newline' '
+       test_must_fail git clone "$GIT_DAEMON_URL/repo$LF.git" dst 2>stderr &&
+       test_i18ngrep newline.is.forbidden stderr
+'
+
 test_remote_error()
 {
        do_export=YesPlease
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