Skip to content

Commit aeeb2d4

Browse files
peffgitster
authored andcommittedJul 28, 2017
connect: reject paths that look like command line options
If we get a repo path like "-repo.git", we may try to invoke "git-upload-pack -repo.git". This is going to fail, since upload-pack will interpret it as a set of bogus options. But let's reject this before we even run the sub-program, since we would not want to allow any mischief with repo names that actually are real command-line options. You can still ask for such a path via git-daemon, but there's no security problem there, because git-daemon enters the repo itself and then passes "." on the command line. Signed-off-by: Jeff King <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3be4cf0 commit aeeb2d4

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
 

‎connect.c

+3
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,9 @@ struct child_process *git_connect(int fd[2], const char *url,
727727
conn = xmalloc(sizeof(*conn));
728728
child_process_init(conn);
729729

730+
if (looks_like_command_line_option(path))
731+
die("strange pathname '%s' blocked", path);
732+
730733
strbuf_addstr(&cmd, prog);
731734
strbuf_addch(&cmd, ' ');
732735
sq_quote_buf(&cmd, path);

‎t/t5810-proto-disable-local.sh

+23
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,27 @@ test_expect_success 'setup repository to clone' '
1111
test_proto "file://" file "file://$PWD"
1212
test_proto "path" file .
1313

14+
test_expect_success 'setup repo with dash' '
15+
git init --bare repo.git &&
16+
git push repo.git HEAD &&
17+
mv repo.git "$PWD/-repo.git"
18+
'
19+
20+
# This will fail even without our rejection because upload-pack will
21+
# complain about the bogus option. So let's make sure that GIT_TRACE
22+
# doesn't show us even running upload-pack.
23+
#
24+
# We must also be sure to use "fetch" and not "clone" here, as the latter
25+
# actually canonicalizes our input into an absolute path (which is fine
26+
# to allow).
27+
test_expect_success 'repo names starting with dash are rejected' '
28+
rm -f trace.out &&
29+
test_must_fail env GIT_TRACE="$PWD/trace.out" git fetch -- -repo.git &&
30+
! grep upload-pack trace.out
31+
'
32+
33+
test_expect_success 'full paths still work' '
34+
git fetch "$PWD/-repo.git"
35+
'
36+
1437
test_done

‎t/t5813-proto-disable-ssh.sh

+14
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,18 @@ test_expect_success 'hostnames starting with dash are rejected' '
2626
! grep ^ssh: stderr
2727
'
2828

29+
test_expect_success 'setup repo with dash' '
30+
git init --bare remote/-repo.git &&
31+
git push remote/-repo.git HEAD
32+
'
33+
34+
test_expect_success 'repo names starting with dash are rejected' '
35+
test_must_fail git clone remote:-repo.git dash-path 2>stderr &&
36+
! grep ^ssh: stderr
37+
'
38+
39+
test_expect_success 'full paths still work' '
40+
git clone "remote:$PWD/remote/-repo.git" dash-path
41+
'
42+
2943
test_done

0 commit comments

Comments
 (0)
Please sign in to comment.