Skip to content

Commit a124133

Browse files
peffgitster
authored andcommitted
fsck: detect submodule urls starting with dash
Urls with leading dashes can cause mischief on older versions of Git. We should detect them so that they can be rejected by receive.fsckObjects, preventing modern versions of git from being a vector by which attacks can spread. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e43aab7 commit a124133

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

fsck.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
6464
FUNC(GITMODULES_PARSE, ERROR) \
6565
FUNC(GITMODULES_NAME, ERROR) \
6666
FUNC(GITMODULES_SYMLINK, ERROR) \
67+
FUNC(GITMODULES_URL, ERROR) \
6768
/* warnings */ \
6869
FUNC(BAD_FILEMODE, WARN) \
6970
FUNC(EMPTY_NAME, WARN) \
@@ -945,6 +946,12 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
945946
FSCK_MSG_GITMODULES_NAME,
946947
"disallowed submodule name: %s",
947948
name);
949+
if (!strcmp(key, "url") && value &&
950+
looks_like_command_line_option(value))
951+
data->ret |= report(data->options, data->obj,
952+
FSCK_MSG_GITMODULES_URL,
953+
"disallowed submodule url: %s",
954+
value);
948955
free(name);
949956

950957
return 0;

t/t7416-submodule-dash-url.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ test_expect_success 'clone can recurse submodule' '
2020
test_cmp expect actual
2121
'
2222

23+
test_expect_success 'fsck accepts protected dash' '
24+
test_when_finished "rm -rf dst" &&
25+
git init --bare dst &&
26+
git -C dst config transfer.fsckObjects true &&
27+
git push dst HEAD
28+
'
29+
2330
test_expect_success 'remove ./ protection from .gitmodules url' '
2431
perl -i -pe "s{\./}{}" .gitmodules &&
2532
git commit -am "drop protection"
@@ -31,4 +38,12 @@ test_expect_success 'clone rejects unprotected dash' '
3138
test_i18ngrep ignoring err
3239
'
3340

41+
test_expect_success 'fsck rejects unprotected dash' '
42+
test_when_finished "rm -rf dst" &&
43+
git init --bare dst &&
44+
git -C dst config transfer.fsckObjects true &&
45+
test_must_fail git push dst HEAD 2>err &&
46+
grep gitmodulesUrl err
47+
'
48+
3449
test_done

0 commit comments

Comments
 (0)