summaryrefslogtreecommitdiff
path: root/t/t7416-submodule-dash-url.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-03-11 22:48:24 (GMT)
committerJeff King <peff@peff.net>2020-03-12 06:56:50 (GMT)
commit07259e74ec1237c836874342c65650bdee8a3993 (patch)
tree5cc2be3aa1dd29e8bee5c2625026b91f2a91555e /t/t7416-submodule-dash-url.sh
parentc716fe4bd917e013bf376a678b3a924447777b2d (diff)
downloadgit-07259e74ec1237c836874342c65650bdee8a3993.zip
git-07259e74ec1237c836874342c65650bdee8a3993.tar.gz
git-07259e74ec1237c836874342c65650bdee8a3993.tar.bz2
fsck: detect gitmodules URLs with embedded newlines
The credential protocol can't handle values with newlines. We already detect and block any such URLs from being used with credential helpers, but let's also add an fsck check to detect and block gitmodules files with such URLs. That will let us notice the problem earlier when transfer.fsckObjects is turned on. And in particular it will prevent bad objects from spreading, which may protect downstream users running older versions of Git. We'll file this under the existing gitmodulesUrl flag, which covers URLs with option injection. There's really no need to distinguish the exact flaw in the URL in this context. Likewise, I've expanded the description of t7416 to cover all types of bogus URLs.
Diffstat (limited to 't/t7416-submodule-dash-url.sh')
-rwxr-xr-xt/t7416-submodule-dash-url.sh18
1 files changed, 17 insertions, 1 deletions
diff --git a/t/t7416-submodule-dash-url.sh b/t/t7416-submodule-dash-url.sh
index 5ba041f..41431b1 100755
--- a/t/t7416-submodule-dash-url.sh
+++ b/t/t7416-submodule-dash-url.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-test_description='check handling of .gitmodule url with dash'
+test_description='check handling of disallowed .gitmodule urls'
. ./test-lib.sh
test_expect_success 'create submodule with protected dash in url' '
@@ -60,4 +60,20 @@ test_expect_success 'trailing backslash is handled correctly' '
test_i18ngrep ! "unknown option" err
'
+test_expect_success 'fsck rejects embedded newline in url' '
+ # create an orphan branch to avoid existing .gitmodules objects
+ git checkout --orphan newline &&
+ cat >.gitmodules <<-\EOF &&
+ [submodule "foo"]
+ url = "https://one.example.com?%0ahost=two.example.com/foo.git"
+ EOF
+ git add .gitmodules &&
+ git commit -m "gitmodules 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