In git, it is possible to handle a remote name with -
character star.
For example, we can add a remote which begins with -
, update it by just using the option --
in the git command (--
separate between command option and the remote name).
But it doesn't work on :
git pull -- "-myremotename" "master"
And, I get this error message :
error: unknown switch `y'
usage: git fetch [<options>] [<repository> [<refspec>...]]
I think that --
option doesn't work in git pull
, because pull
is a combination of git fetch
followed by git merge
, and --
isn't used when making this 2 commands.
Any idea to fix it ?
Prefix the remote name with the word
safe
You can then use it again
As remote names land in the file-system and also are prone to injection as your question shows, please consider the following:
Use only characters from the 3.282 Portable Filename Character Set
Do not use the dash
-
as first character. (ref)Do not use any of the digits
0-9
and lettersa-f
/A-F
within the remote name only (if the name is longer than three characters). Otherwise a remote name may become refused bygit(1)
in the future of your repository. (ref)And additional and more in general:
0-9
..
,_
or-
.a-z
or upperA-Z
.And thanks for asking. It is exactly as you wrote that
git-pull(1)
allows to specify the remote name after--
while that in thegit-fetch(1)
invocation by it, the remote name is passed verbatim into the arguments list.It does not look like an ordinary injection that allows to get ownage of the whole bakery. The only thing that can be injected to
git-fetch(1)
is a single parameter by the configuredremote.<name>
.E.g. with a single remote named
--all
we can sendgit-pull(1)
(and, via),git-fetch(1)
into child recursion. That is fun but also spamstty
Example
Name of the remote:
--all
Process tree of
git pull -- --all
(limited to 6 lines):Does
git-fetch(1)
tricks itself here already? Sort of, but only if--jobs=1
. With--jobs=2
or higher than2
,git-fetch(2)
does process the option more sequentially and not all-over and again and again. But only if there are at least two remotes.Well, looks like.
git-fetch --all
has no sanity check to detect if it is re-entrant for the same remote name nor seems to have an option with its own argument to denote the remote (either by name or URL) which could prevent that.(git version 2.25.1)