Skip to content

Commit

Permalink
git_connect: clear GIT_* environment for ssh
Browse files Browse the repository at this point in the history
When we "switch" to another local repository to run the server
side of a fetch or push, we must clear the variables in
local_repo_env so that our local $GIT_DIR, etc, do not
pollute the upload-pack or receive-pack that is executing in
the "remote" repository.

We have never done so for ssh connections. For the most
part, nobody has noticed because ssh will not pass unknown
environment variables by default. However, it is not out of
the question for a user to configure ssh to pass along GIT_*
variables using SendEnv/AcceptEnv.

We can demonstrate the problem by using "git -c" on a local
command and seeing its impact on a remote repository.  This
config ends up in $GIT_CONFIG_PARAMETERS. In the local case,
the config has no impact, but in the ssh transport, it does
(our test script has a fake ssh that passes through all
environment variables; this isn't normal, but does simulate
one possible setup).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 4, 2015
1 parent a17c56c commit aab4043
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ struct child_process *git_connect(int fd[2], const char *url,
strbuf_addch(&cmd, ' ');
sq_quote_buf(&cmd, path);

/* remove repo-local variables from the environment */
conn->env = local_repo_env;
conn->in = conn->out = -1;
if (protocol == PROTO_SSH) {
const char *ssh;
Expand Down Expand Up @@ -778,8 +780,6 @@ struct child_process *git_connect(int fd[2], const char *url,
}
argv_array_push(&conn->args, ssh_host);
} else {
/* remove repo-local variables from the environment */
conn->env = local_repo_env;
conn->use_shell = 1;
}
argv_array_push(&conn->args, cmd.buf);
Expand Down
34 changes: 34 additions & 0 deletions t/t5507-remote-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

test_description='check environment showed to remote side of transports'
. ./test-lib.sh

test_expect_success 'set up "remote" push situation' '
test_commit one &&
git config push.default current &&
git init remote
'

test_expect_success 'set up fake ssh' '
GIT_SSH_COMMAND="f() {
cd \"\$TRASH_DIRECTORY\" &&
eval \"\$2\"
}; f" &&
export GIT_SSH_COMMAND &&
export TRASH_DIRECTORY
'

# due to receive.denyCurrentBranch=true
test_expect_success 'confirm default push fails' '
test_must_fail git push remote
'

test_expect_success 'config does not travel over same-machine push' '
test_must_fail git -c receive.denyCurrentBranch=false push remote
'

test_expect_success 'config does not travel over ssh push' '
test_must_fail git -c receive.denyCurrentBranch=false push host:remote
'

test_done

0 comments on commit aab4043

Please sign in to comment.