3be4cf09cd
If you have a GIT_PROXY_COMMAND configured, we will run it with the host/port on the command-line. If a URL contains a mischievous host like "--foo", we don't know how the proxy command may handle it. It's likely to break, but it may also do something dangerous and unwanted (technically it could even do something useful, but that seems unlikely). We should err on the side of caution and reject this before we even run the command. The hostname check matches the one we do in a similar circumstance for ssh. The port check is not present for ssh, but there it's not necessary because the syntax is "-p <port>", and there's no ambiguity on the parsing side. It's not clear whether you can actually get a negative port to the proxy here or not. Doing: git fetch git://remote:-1234/repo.git keeps the "-1234" as part of the hostname, with the default port of 9418. But it's a good idea to keep this check close to the point of running the command to make it clear that there's no way to circumvent it (and at worst it serves as a belt-and-suspenders check). Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
49 lines
1014 B
Bash
Executable File
49 lines
1014 B
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='fetching via git:// using core.gitproxy'
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup remote repo' '
|
|
git init remote &&
|
|
(cd remote &&
|
|
echo content >file &&
|
|
git add file &&
|
|
git commit -m one
|
|
)
|
|
'
|
|
|
|
cat >proxy <<'EOF'
|
|
#!/bin/sh
|
|
echo >&2 "proxying for $*"
|
|
cmd=`"$PERL_PATH" -e '
|
|
read(STDIN, $buf, 4);
|
|
my $n = hex($buf) - 4;
|
|
read(STDIN, $buf, $n);
|
|
my ($cmd, $other) = split /\0/, $buf;
|
|
# drop absolute-path on repo name
|
|
$cmd =~ s{ /}{ };
|
|
print $cmd;
|
|
'`
|
|
echo >&2 "Running '$cmd'"
|
|
exec $cmd
|
|
EOF
|
|
chmod +x proxy
|
|
test_expect_success 'setup local repo' '
|
|
git remote add fake git://example.com/remote &&
|
|
git config core.gitproxy ./proxy
|
|
'
|
|
|
|
test_expect_success 'fetch through proxy works' '
|
|
git fetch fake &&
|
|
echo one >expect &&
|
|
git log -1 --format=%s FETCH_HEAD >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'funny hostnames are rejected before running proxy' '
|
|
test_must_fail git fetch git://-remote/repo.git 2>stderr &&
|
|
! grep "proxying for" stderr
|
|
'
|
|
|
|
test_done
|