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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 24, 2018 at 04:37 UTC a124133e1e6ab5c7a9fef6d0e6bcb084e3455b46
2 files changed +22
fsck.c
+7
@@ -64,6 +64,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
64 FUNC(GITMODULES_PARSE, ERROR) \
65 FUNC(GITMODULES_NAME, ERROR) \
66 FUNC(GITMODULES_SYMLINK, ERROR) \
67 + FUNC(GITMODULES_URL, ERROR) \
68 /* warnings */ \
69 FUNC(BAD_FILEMODE, WARN) \
70 FUNC(EMPTY_NAME, WARN) \
@@ -945,6 +946,12 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
946 FSCK_MSG_GITMODULES_NAME,
947 "disallowed submodule name: %s",
948 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);
955 free(name);
956
957 return 0;
t/t7416-submodule-dash-url.sh
+15
@@ -20,6 +20,13 @@ test_expect_success 'clone can recurse submodule' '
20 test_cmp expect actual
21 '
22
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 +
30 test_expect_success 'remove ./ protection from .gitmodules url' '
31 perl -i -pe "s{\./}{}" .gitmodules &&
32 git commit -am "drop protection"
@@ -31,4 +38,12 @@ test_expect_success 'clone rejects unprotected dash' '
38 test_i18ngrep ignoring err
39 '
40
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 +
49 test_done