Skip to content

Commit 635ff67

Browse files
committed
Merge branch 'jk/forbid-lf-in-git-url' into maint
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 8ff9ec4 + 6aed567 commit 635ff67

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
@@ -1082,7 +1082,7 @@ static int check_submodule_url(const char *url)
10821082
if (looks_like_command_line_option(url))
10831083
return -1;
10841084

1085-
if (submodule_url_is_relative(url)) {
1085+
if (submodule_url_is_relative(url) || starts_with(url, "git://")) {
10861086
char *decoded;
10871087
const char *next;
10881088
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)