Skip to content

Commit 07259e7

Browse files
committed
fsck: detect gitmodules URLs with embedded newlines
The credential protocol can't handle values with newlines. We already detect and block any such URLs from being used with credential helpers, but let's also add an fsck check to detect and block gitmodules files with such URLs. That will let us notice the problem earlier when transfer.fsckObjects is turned on. And in particular it will prevent bad objects from spreading, which may protect downstream users running older versions of Git. We'll file this under the existing gitmodulesUrl flag, which covers URLs with option injection. There's really no need to distinguish the exact flaw in the URL in this context. Likewise, I've expanded the description of t7416 to cover all types of bogus URLs.
1 parent c716fe4 commit 07259e7

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

fsck.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "packfile.h"
1515
#include "submodule-config.h"
1616
#include "config.h"
17+
#include "credential.h"
1718

1819
static struct oidset gitmodules_found = OIDSET_INIT;
1920
static struct oidset gitmodules_done = OIDSET_INIT;
@@ -941,6 +942,19 @@ static int fsck_tag(struct tag *tag, const char *data,
941942
return fsck_tag_buffer(tag, data, size, options);
942943
}
943944

945+
static int check_submodule_url(const char *url)
946+
{
947+
struct credential c = CREDENTIAL_INIT;
948+
int ret;
949+
950+
if (looks_like_command_line_option(url))
951+
return -1;
952+
953+
ret = credential_from_url_gently(&c, url, 1);
954+
credential_clear(&c);
955+
return ret;
956+
}
957+
944958
struct fsck_gitmodules_data {
945959
struct object *obj;
946960
struct fsck_options *options;
@@ -965,7 +979,7 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
965979
"disallowed submodule name: %s",
966980
name);
967981
if (!strcmp(key, "url") && value &&
968-
looks_like_command_line_option(value))
982+
check_submodule_url(value) < 0)
969983
data->ret |= report(data->options, data->obj,
970984
FSCK_MSG_GITMODULES_URL,
971985
"disallowed submodule url: %s",

t/t7416-submodule-dash-url.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
test_description='check handling of .gitmodule url with dash'
3+
test_description='check handling of disallowed .gitmodule urls'
44
. ./test-lib.sh
55

66
test_expect_success 'create submodule with protected dash in url' '
@@ -60,4 +60,20 @@ test_expect_success 'trailing backslash is handled correctly' '
6060
test_i18ngrep ! "unknown option" err
6161
'
6262

63+
test_expect_success 'fsck rejects embedded newline in url' '
64+
# create an orphan branch to avoid existing .gitmodules objects
65+
git checkout --orphan newline &&
66+
cat >.gitmodules <<-\EOF &&
67+
[submodule "foo"]
68+
url = "https://one.example.com?%0ahost=two.example.com/foo.git"
69+
EOF
70+
git add .gitmodules &&
71+
git commit -m "gitmodules with newline" &&
72+
test_when_finished "rm -rf dst" &&
73+
git init --bare dst &&
74+
git -C dst config transfer.fsckObjects true &&
75+
test_must_fail git push dst HEAD 2>err &&
76+
grep gitmodulesUrl err
77+
'
78+
6379
test_done

0 commit comments

Comments
 (0)