Skip to content

Commit c7b1aaf

Browse files
committed
Merge branch 'jk/forbid-lf-in-git-url'
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
2 parents 9e409d7 + 6aed567 commit c7b1aaf

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

connect.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,8 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
11601160
target_host = xstrdup(hostandport);
11611161

11621162
transport_check_allowed("git");
1163+
if (strchr(target_host, '\n') || strchr(path, '\n'))
1164+
die(_("newline is forbidden in git:// hosts and repo paths"));
11631165

11641166
/*
11651167
* These underlying connection commands die() if they

fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ static int check_submodule_url(const char *url)
11101110
if (looks_like_command_line_option(url))
11111111
return -1;
11121112

1113-
if (submodule_url_is_relative(url)) {
1113+
if (submodule_url_is_relative(url) || starts_with(url, "git://")) {
11141114
char *decoded;
11151115
const char *next;
11161116
int has_nl;

t/t5570-git-daemon.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ test_expect_success 'fetch notices corrupt idx' '
103103
)
104104
'
105105

106+
test_expect_success 'client refuses to ask for repo with newline' '
107+
test_must_fail git clone "$GIT_DAEMON_URL/repo$LF.git" dst 2>stderr &&
108+
test_i18ngrep newline.is.forbidden stderr
109+
'
110+
106111
test_remote_error()
107112
{
108113
do_export=YesPlease

t/t7416-submodule-dash-url.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,19 @@ test_expect_success 'fsck rejects embedded newline in relative url' '
201201
grep gitmodulesUrl err
202202
'
203203

204+
test_expect_success 'fsck rejects embedded newline in git url' '
205+
git checkout --orphan git-newline &&
206+
cat >.gitmodules <<-\EOF &&
207+
[submodule "foo"]
208+
url = "git://example.com:1234/repo%0a.git"
209+
EOF
210+
git add .gitmodules &&
211+
git commit -m "git url with newline" &&
212+
test_when_finished "rm -rf dst" &&
213+
git init --bare dst &&
214+
git -C dst config transfer.fsckObjects true &&
215+
test_must_fail git push dst HEAD 2>err &&
216+
grep gitmodulesUrl err
217+
'
218+
204219
test_done

0 commit comments

Comments
 (0)