|
|
c98d86 |
From d819a25360ba38dfec31e37413963adf5688db80 Mon Sep 17 00:00:00 2001
|
|
|
c98d86 |
From: Jeff King <peff@peff.net>
|
|
|
c98d86 |
Date: Mon, 24 Sep 2018 04:32:15 -0400
|
|
|
c98d86 |
Subject: [PATCH 1/2] submodule--helper: use "--" to signal end of clone
|
|
|
c98d86 |
options
|
|
|
c98d86 |
|
|
|
c98d86 |
commit 98afac7a7cefdca0d2c4917dd8066a59f7088265 upstream.
|
|
|
c98d86 |
|
|
|
c98d86 |
When we clone a submodule, we call "git clone $url $path".
|
|
|
c98d86 |
But there's nothing to say that those components can't begin
|
|
|
c98d86 |
with a dash themselves, confusing git-clone into thinking
|
|
|
c98d86 |
they're options. Let's pass "--" to make it clear what we
|
|
|
c98d86 |
expect.
|
|
|
c98d86 |
|
|
|
c98d86 |
There's no test here, because it's actually quite hard to
|
|
|
c98d86 |
make these names work, even with "git clone" parsing them
|
|
|
c98d86 |
correctly. And we're going to restrict these cases even
|
|
|
c98d86 |
further in future commits. So we'll leave off testing until
|
|
|
c98d86 |
then; this is just the minimal fix to prevent us from doing
|
|
|
c98d86 |
something stupid with a badly formed entry.
|
|
|
c98d86 |
|
|
|
c98d86 |
[jn: backported to 2.1.y by applying to git-submodule.sh
|
|
|
c98d86 |
instead of submodule--helper]
|
|
|
c98d86 |
|
|
|
c98d86 |
Reported-by: joernchen <joernchen@phenoelit.de>
|
|
|
c98d86 |
Signed-off-by: Jeff King <peff@peff.net>
|
|
|
c98d86 |
Signed-off-by: Junio C Hamano <gitster@pobox.com>
|
|
|
c98d86 |
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
|
|
|
c98d86 |
|
|
|
c98d86 |
submodule-config: ban submodule urls that start with dash
|
|
|
c98d86 |
|
|
|
c98d86 |
commit f6adec4e329ef0e25e14c63b735a5956dc67b8bc upstream.
|
|
|
c98d86 |
|
|
|
c98d86 |
The previous commit taught the submodule code to invoke our
|
|
|
c98d86 |
"git clone $url $path" with a "--" separator so that we
|
|
|
c98d86 |
aren't confused by urls or paths that start with dashes.
|
|
|
c98d86 |
|
|
|
c98d86 |
However, that's just one code path. It's not clear if there
|
|
|
c98d86 |
are others, and it would be an easy mistake to add one in
|
|
|
c98d86 |
the future. Moreover, even with the fix in the previous
|
|
|
c98d86 |
commit, it's quite hard to actually do anything useful with
|
|
|
c98d86 |
such an entry. Any url starting with a dash must fall into
|
|
|
c98d86 |
one of three categories:
|
|
|
c98d86 |
|
|
|
c98d86 |
- it's meant as a file url, like "-path". But then any
|
|
|
c98d86 |
clone is not going to have the matching path, since it's
|
|
|
c98d86 |
by definition relative inside the newly created clone. If
|
|
|
c98d86 |
you spell it as "./-path", the submodule code sees the
|
|
|
c98d86 |
"/" and translates this to an absolute path, so it at
|
|
|
c98d86 |
least works (assuming the receiver has the same
|
|
|
c98d86 |
filesystem layout as you). But that trick does not apply
|
|
|
c98d86 |
for a bare "-path".
|
|
|
c98d86 |
|
|
|
c98d86 |
- it's meant as an ssh url, like "-host:path". But this
|
|
|
c98d86 |
already doesn't work, as we explicitly disallow ssh
|
|
|
c98d86 |
hostnames that begin with a dash (to avoid option
|
|
|
c98d86 |
injection against ssh).
|
|
|
c98d86 |
|
|
|
c98d86 |
- it's a remote-helper scheme, like "-scheme::data". This
|
|
|
c98d86 |
_could_ work if the receiver bends over backwards and
|
|
|
c98d86 |
creates a funny-named helper like "git-remote--scheme".
|
|
|
c98d86 |
But normally there would not be any helper that matches.
|
|
|
c98d86 |
|
|
|
c98d86 |
Since such a url does not work today and is not likely to do
|
|
|
c98d86 |
anything useful in the future, let's simply disallow them
|
|
|
c98d86 |
entirely. That protects the existing "git clone" path (in a
|
|
|
c98d86 |
belt-and-suspenders way), along with any others that might
|
|
|
c98d86 |
exist.
|
|
|
c98d86 |
|
|
|
c98d86 |
[jn: backported to 2.1.y by porting to shell]
|
|
|
c98d86 |
[pc: backported to 1.8.3.1 by using $sm_path instead of $displayname
|
|
|
c98d86 |
and split tests into a separate commit]
|
|
|
c98d86 |
|
|
|
c98d86 |
Signed-off-by: Jeff King <peff@peff.net>
|
|
|
c98d86 |
Signed-off-by: Junio C Hamano <gitster@pobox.com>
|
|
|
c98d86 |
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
|
|
|
c98d86 |
|
|
|
c98d86 |
submodule-config: ban submodule paths that start with a dash
|
|
|
c98d86 |
|
|
|
c98d86 |
commit 273c61496f88c6495b886acb1041fe57965151da upstream.
|
|
|
c98d86 |
|
|
|
c98d86 |
We recently banned submodule urls that look like
|
|
|
c98d86 |
command-line options. This is the matching change to ban
|
|
|
c98d86 |
leading-dash paths.
|
|
|
c98d86 |
|
|
|
c98d86 |
As with the urls, this should not break any use cases that
|
|
|
c98d86 |
currently work. Even with our "--" separator passed to
|
|
|
c98d86 |
git-clone, git-submodule.sh gets confused. Without the code
|
|
|
c98d86 |
portion of this patch, the clone of "-sub" added in t7417
|
|
|
c98d86 |
would yield results like:
|
|
|
c98d86 |
|
|
|
c98d86 |
/path/to/git-submodule: 410: cd: Illegal option -s
|
|
|
c98d86 |
/path/to/git-submodule: 417: cd: Illegal option -s
|
|
|
c98d86 |
/path/to/git-submodule: 410: cd: Illegal option -s
|
|
|
c98d86 |
/path/to/git-submodule: 417: cd: Illegal option -s
|
|
|
c98d86 |
Fetched in submodule path '-sub', but it did not contain b56243f8f4eb91b2f1f8109452e659f14dd3fbe4. D
|
|
|
c98d86 |
irect fetching of that commit failed.
|
|
|
c98d86 |
|
|
|
c98d86 |
Moreover, naively adding such a submodule doesn't work:
|
|
|
c98d86 |
|
|
|
c98d86 |
$ git submodule add $url -sub
|
|
|
c98d86 |
The following path is ignored by one of your .gitignore files:
|
|
|
c98d86 |
-sub
|
|
|
c98d86 |
|
|
|
c98d86 |
even though there is no such ignore pattern (the test script
|
|
|
c98d86 |
hacks around this with a well-placed "git mv").
|
|
|
c98d86 |
|
|
|
c98d86 |
Unlike leading-dash urls, though, it's possible that such a
|
|
|
c98d86 |
path _could_ be useful if we eventually made it work. So
|
|
|
c98d86 |
this commit should be seen not as recommending a particular
|
|
|
c98d86 |
policy, but rather temporarily closing off a broken and
|
|
|
c98d86 |
possibly dangerous code-path. We may revisit this decision
|
|
|
c98d86 |
later.
|
|
|
c98d86 |
|
|
|
c98d86 |
[jn: ported to git-submodule.sh
|
|
|
c98d86 |
pc: split the test into a separate commit ]
|
|
|
c98d86 |
|
|
|
c98d86 |
fsck: detect submodule urls starting with dash
|
|
|
c98d86 |
|
|
|
c98d86 |
commit a124133e1e6ab5c7a9fef6d0e6bcb084e3455b46 upstream.
|
|
|
c98d86 |
|
|
|
c98d86 |
Urls with leading dashes can cause mischief on older
|
|
|
c98d86 |
versions of Git. We should detect them so that they can be
|
|
|
c98d86 |
rejected by receive.fsckObjects, preventing modern versions
|
|
|
c98d86 |
of git from being a vector by which attacks can spread.
|
|
|
c98d86 |
|
|
|
c98d86 |
[jn: backported to 2.1.y: using error_func instead of report
|
|
|
c98d86 |
to report fsck errors]
|
|
|
c98d86 |
|
|
|
c98d86 |
[pc: split tests into a separate commit]
|
|
|
c98d86 |
|
|
|
c98d86 |
Signed-off-by: Jeff King <peff@peff.net>
|
|
|
c98d86 |
Signed-off-by: Junio C Hamano <gitster@pobox.com>
|
|
|
c98d86 |
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
|
|
|
c98d86 |
|
|
|
c98d86 |
fsck: detect submodule paths starting with dash
|
|
|
c98d86 |
|
|
|
c98d86 |
commit 1a7fd1fb2998002da6e9ff2ee46e1bdd25ee8404 upstream.
|
|
|
c98d86 |
|
|
|
c98d86 |
As with urls, submodule paths with dashes are ignored by
|
|
|
c98d86 |
git, but may end up confusing older versions. Detecting them
|
|
|
c98d86 |
via fsck lets us prevent modern versions of git from being a
|
|
|
c98d86 |
vector to spread broken .gitmodules to older versions.
|
|
|
c98d86 |
|
|
|
c98d86 |
Compared to blocking leading-dash urls, though, this
|
|
|
c98d86 |
detection may be less of a good idea:
|
|
|
c98d86 |
|
|
|
c98d86 |
1. While such paths provide confusing and broken results,
|
|
|
c98d86 |
they don't seem to actually work as option injections
|
|
|
c98d86 |
against anything except "cd". In particular, the
|
|
|
c98d86 |
submodule code seems to canonicalize to an absolute
|
|
|
c98d86 |
path before running "git clone" (so it passes
|
|
|
c98d86 |
/your/clone/-sub).
|
|
|
c98d86 |
|
|
|
c98d86 |
2. It's more likely that we may one day make such names
|
|
|
c98d86 |
actually work correctly. Even after we revert this fsck
|
|
|
c98d86 |
check, it will continue to be a hassle until hosting
|
|
|
c98d86 |
servers are all updated.
|
|
|
c98d86 |
|
|
|
c98d86 |
On the other hand, it's not entirely clear that the behavior
|
|
|
c98d86 |
in older versions is safe. And if we do want to eventually
|
|
|
c98d86 |
allow this, we may end up doing so with a special syntax
|
|
|
c98d86 |
anyway (e.g., writing "./-sub" in the .gitmodules file, and
|
|
|
c98d86 |
teaching the submodule code to canonicalize it when
|
|
|
c98d86 |
comparing).
|
|
|
c98d86 |
|
|
|
c98d86 |
So on balance, this is probably a good protection.
|
|
|
c98d86 |
|
|
|
c98d86 |
[jn: backported to 2.1.y: using error_func instead of report
|
|
|
c98d86 |
to report fsck errors]
|
|
|
c98d86 |
|
|
|
c98d86 |
[pc: split test to a separate commit]
|
|
|
c98d86 |
---
|
|
|
c98d86 |
fsck.c | 10 ++++++++++
|
|
|
c98d86 |
git-submodule.sh | 20 +++++++++++++++-----
|
|
|
c98d86 |
2 files changed, 25 insertions(+), 5 deletions(-)
|
|
|
c98d86 |
|
|
|
c98d86 |
diff --git a/fsck.c b/fsck.c
|
|
|
c98d86 |
index 811724125..90d641066 100644
|
|
|
c98d86 |
--- a/fsck.c
|
|
|
c98d86 |
+++ b/fsck.c
|
|
|
c98d86 |
@@ -442,6 +442,16 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
|
|
|
c98d86 |
data->ret += data->error_func(data->obj, FSCK_ERROR,
|
|
|
c98d86 |
"disallowed submodule name: %s",
|
|
|
c98d86 |
name);
|
|
|
c98d86 |
+ if (!strcmp(key, "url") && value &&
|
|
|
c98d86 |
+ looks_like_command_line_option(value))
|
|
|
c98d86 |
+ data->ret += data->error_func(data->obj, FSCK_ERROR,
|
|
|
c98d86 |
+ "disallowed submodule url: %s",
|
|
|
c98d86 |
+ value);
|
|
|
c98d86 |
+ if (!strcmp(key, "path") && value &&
|
|
|
c98d86 |
+ looks_like_command_line_option(value))
|
|
|
c98d86 |
+ data->ret += data->error_func(data->obj, FSCK_ERROR,
|
|
|
c98d86 |
+ "disallowed submodule path: %s",
|
|
|
c98d86 |
+ value);
|
|
|
c98d86 |
free(name);
|
|
|
c98d86 |
|
|
|
c98d86 |
return 0;
|
|
|
c98d86 |
diff --git a/git-submodule.sh b/git-submodule.sh
|
|
|
c98d86 |
index e958ce840..b5176ecc3 100755
|
|
|
c98d86 |
--- a/git-submodule.sh
|
|
|
c98d86 |
+++ b/git-submodule.sh
|
|
|
c98d86 |
@@ -205,6 +205,11 @@ module_name()
|
|
|
c98d86 |
re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
|
|
|
c98d86 |
name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
|
|
|
c98d86 |
sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
|
|
|
c98d86 |
+ case "$sm_path" in
|
|
|
c98d86 |
+ -*)
|
|
|
c98d86 |
+ die "$(eval_gettext "Submodule path '\$sm_path' may be interpreted as a command-line option")"
|
|
|
c98d86 |
+ ;;
|
|
|
c98d86 |
+ esac
|
|
|
c98d86 |
test -z "$name" &&
|
|
|
c98d86 |
die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")"
|
|
|
c98d86 |
check_module_name "$name"
|
|
|
c98d86 |
@@ -248,7 +253,7 @@ module_clone()
|
|
|
c98d86 |
(
|
|
|
c98d86 |
clear_local_git_env
|
|
|
c98d86 |
git clone $quiet -n ${reference:+"$reference"} \
|
|
|
c98d86 |
- --separate-git-dir "$gitdir" "$url" "$sm_path"
|
|
|
c98d86 |
+ --separate-git-dir "$gitdir" -- "$url" "$sm_path"
|
|
|
c98d86 |
) ||
|
|
|
c98d86 |
die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")"
|
|
|
c98d86 |
fi
|
|
|
c98d86 |
@@ -547,11 +552,13 @@ cmd_init()
|
|
|
c98d86 |
if test -z "$(git config "submodule.$name.url")"
|
|
|
c98d86 |
then
|
|
|
c98d86 |
url=$(git config -f .gitmodules submodule."$name".url)
|
|
|
c98d86 |
- test -z "$url" &&
|
|
|
c98d86 |
- die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
|
|
|
c98d86 |
-
|
|
|
c98d86 |
- # Possibly a url relative to parent
|
|
|
c98d86 |
case "$url" in
|
|
|
c98d86 |
+ "")
|
|
|
c98d86 |
+ die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
|
|
|
c98d86 |
+ ;;
|
|
|
c98d86 |
+ -*)
|
|
|
c98d86 |
+ die "$(eval_gettext "Submodule at path '\$sm_path' has url '\$url' which may be interpreted as a command-line option")"
|
|
|
c98d86 |
+ ;;
|
|
|
c98d86 |
./*|../*)
|
|
|
c98d86 |
url=$(resolve_relative_url "$url") || exit
|
|
|
c98d86 |
;;
|
|
|
c98d86 |
@@ -1213,6 +1220,9 @@ cmd_sync()
|
|
|
c98d86 |
|
|
|
c98d86 |
# Possibly a url relative to parent
|
|
|
c98d86 |
case "$url" in
|
|
|
c98d86 |
+ -*)
|
|
|
c98d86 |
+ die "$(eval_gettext "Submodule at path '\$sm_path' has url '\$url' which may be interpreted as a command-line option")"
|
|
|
c98d86 |
+ ;;
|
|
|
c98d86 |
./*|../*)
|
|
|
c98d86 |
# rewrite foo/bar as ../.. to find path from
|
|
|
c98d86 |
# submodule work tree to superproject work tree
|
|
|
c98d86 |
--
|
|
|
c98d86 |
2.14.4
|
|
|
c98d86 |
|