Revision 3ec804490a265f4c418a321428c12f3f18b7eff5 authored by Jeff King on 29 April 2017, 12:36:44 UTC, committed by Junio C Hamano on 05 May 2017, 03:07:27 UTC
When a remote server uses git-shell, the client side will
connect to it like:

  ssh server "git-upload-pack 'foo.git'"

and we literally exec ("git-upload-pack", "foo.git"). In
early versions of upload-pack and receive-pack, we took a
repository argument and nothing else. But over time they
learned to accept dashed options. If the user passes a
repository name that starts with a dash, the results are
confusing at best (we complain of a bogus option instead of
a non-existent repository) and malicious at worst (the user
can start an interactive pager via "--help").

We could pass "--" to the sub-process to make sure the
user's argument is interpreted as a branch name. I.e.:

  git-upload-pack -- -foo.git

But adding "--" automatically would make us inconsistent
with a normal shell (i.e., when git-shell is not in use),
where "-foo.git" would still be an error. For that case, the
client would have to specify the "--", but they can't do so
reliably, as existing versions of git-shell do not allow
more than a single argument.

The simplest thing is to simply disallow "-" at the start of
the repo name argument. This hasn't worked either with or
without git-shell since version 1.0.0, and nobody has
complained.

Note that this patch just applies to do_generic_cmd(), which
runs upload-pack, receive-pack, and upload-archive. There
are two other types of commands that git-shell runs:

  - do_cvs_cmd(), but this already restricts the argument to
    be the literal string "server"

  - admin-provided commands in the git-shell-commands
    directory. We'll pass along arbitrary arguments there,
    so these commands could have similar problems. But these
    commands might actually understand dashed arguments, so
    we cannot just block them here. It's up to the writer of
    the commands to make sure they are safe. With great
    power comes great responsibility.

Reported-by: Timo Schmid <tschmid@ernw.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7654286
History
File Mode Size
RelNotes
howto
technical
.gitattributes -rw-r--r-- 17 bytes
.gitignore -rw-r--r-- 135 bytes
CodingGuidelines -rw-r--r-- 18.1 KB
Makefile -rw-r--r-- 12.3 KB
SubmittingPatches -rw-r--r-- 18.9 KB
asciidoc.conf -rw-r--r-- 2.3 KB
blame-options.txt -rw-r--r-- 3.8 KB
build-docdep.perl -rwxr-xr-x 968 bytes
cat-texi.perl -rwxr-xr-x 776 bytes
cmd-list.perl -rwxr-xr-x 1.4 KB
config.txt -rw-r--r-- 106.1 KB
date-formats.txt -rw-r--r-- 850 bytes
diff-config.txt -rw-r--r-- 7.3 KB
diff-format.txt -rw-r--r-- 5.5 KB
diff-generate-patch.txt -rw-r--r-- 6.4 KB
diff-options.txt -rw-r--r-- 19.6 KB
docbook-xsl.css -rw-r--r-- 4.5 KB
docbook.xsl -rw-r--r-- 362 bytes
everyday.txto -rw-r--r-- 246 bytes
fetch-options.txt -rw-r--r-- 5.3 KB
fix-texi.perl -rwxr-xr-x 309 bytes
fmt-merge-msg-config.txt -rw-r--r-- 378 bytes
git-add.txt -rw-r--r-- 14.1 KB
git-am.txt -rw-r--r-- 7.0 KB
git-annotate.txt -rw-r--r-- 752 bytes
git-apply.txt -rw-r--r-- 10.1 KB
git-archimport.txt -rw-r--r-- 3.9 KB
git-archive.txt -rw-r--r-- 6.2 KB
git-bisect-lk2009.txt -rw-r--r-- 48.1 KB
git-bisect.txt -rw-r--r-- 12.4 KB
git-blame.txt -rw-r--r-- 7.8 KB
git-branch.txt -rw-r--r-- 10.2 KB
git-bundle.txt -rw-r--r-- 6.9 KB
git-cat-file.txt -rw-r--r-- 5.1 KB
git-check-attr.txt -rw-r--r-- 3.1 KB
git-check-ignore.txt -rw-r--r-- 3.8 KB
git-check-mailmap.txt -rw-r--r-- 946 bytes
git-check-ref-format.txt -rw-r--r-- 4.1 KB
git-checkout-index.txt -rw-r--r-- 5.3 KB
git-checkout.txt -rw-r--r-- 15.9 KB
git-cherry-pick.txt -rw-r--r-- 7.9 KB
git-cherry.txt -rw-r--r-- 3.5 KB
git-citool.txt -rw-r--r-- 543 bytes
git-clean.txt -rw-r--r-- 4.3 KB
git-clone.txt -rw-r--r-- 9.6 KB
git-column.txt -rw-r--r-- 1.1 KB
git-commit-tree.txt -rw-r--r-- 2.9 KB
git-commit.txt -rw-r--r-- 15.7 KB
git-config.txt -rw-r--r-- 12.9 KB
git-count-objects.txt -rw-r--r-- 1.1 KB
git-credential-cache--daemon.txt -rw-r--r-- 864 bytes
git-credential-cache.txt -rw-r--r-- 2.1 KB
git-credential-store.txt -rw-r--r-- 3.4 KB
git-credential.txt -rw-r--r-- 5.7 KB
git-cvsexportcommit.txt -rw-r--r-- 3.1 KB
git-cvsimport.txt -rw-r--r-- 7.6 KB
git-cvsserver.txt -rw-r--r-- 15.2 KB
git-daemon.txt -rw-r--r-- 11.6 KB
git-describe.txt -rw-r--r-- 5.9 KB
git-diff-files.txt -rw-r--r-- 1.2 KB
git-diff-index.txt -rw-r--r-- 4.5 KB
git-diff-tree.txt -rw-r--r-- 5.3 KB
git-diff.txt -rw-r--r-- 5.5 KB
git-difftool.txt -rw-r--r-- 4.5 KB
git-fast-export.txt -rw-r--r-- 7.9 KB
git-fast-import.txt -rw-r--r-- 53.7 KB
git-fetch-pack.txt -rw-r--r-- 3.3 KB
git-fetch.txt -rw-r--r-- 5.6 KB
git-filter-branch.txt -rw-r--r-- 18.2 KB
git-fmt-merge-msg.txt -rw-r--r-- 1.5 KB
git-for-each-ref.txt -rw-r--r-- 6.0 KB
git-format-patch.txt -rw-r--r-- 19.2 KB
git-fsck-objects.txt -rw-r--r-- 354 bytes
git-fsck.txt -rw-r--r-- 4.5 KB
git-gc.txt -rw-r--r-- 5.7 KB
git-get-tar-commit-id.txt -rw-r--r-- 737 bytes
git-grep.txt -rw-r--r-- 7.8 KB
git-gui.txt -rw-r--r-- 3.5 KB
git-hash-object.txt -rw-r--r-- 2.1 KB
git-help.txt -rw-r--r-- 6.0 KB
git-http-backend.txt -rw-r--r-- 9.8 KB
git-http-fetch.txt -rw-r--r-- 1.1 KB
git-http-push.txt -rw-r--r-- 2.9 KB
git-imap-send.txt -rw-r--r-- 4.8 KB
git-index-pack.txt -rw-r--r-- 3.4 KB
git-init-db.txt -rw-r--r-- 409 bytes
git-init.txt -rw-r--r-- 4.7 KB
git-instaweb.txt -rw-r--r-- 2.2 KB
git-interpret-trailers.txt -rw-r--r-- 10.7 KB
git-log.txt -rw-r--r-- 6.2 KB
git-ls-files.txt -rw-r--r-- 6.1 KB
git-ls-remote.txt -rw-r--r-- 2.5 KB
git-ls-tree.txt -rw-r--r-- 2.9 KB
git-mailinfo.txt -rw-r--r-- 3.2 KB
git-mailsplit.txt -rw-r--r-- 1.2 KB
git-merge-base.txt -rw-r--r-- 5.6 KB
git-merge-file.txt -rw-r--r-- 2.8 KB
git-merge-index.txt -rw-r--r-- 2.4 KB
git-merge-one-file.txt -rw-r--r-- 387 bytes
git-merge-tree.txt -rw-r--r-- 750 bytes
git-merge.txt -rw-r--r-- 12.0 KB
git-mergetool--lib.txt -rw-r--r-- 1.2 KB
git-mergetool.txt -rw-r--r-- 3.4 KB
git-mktag.txt -rw-r--r-- 806 bytes
git-mktree.txt -rw-r--r-- 1.1 KB
git-mv.txt -rw-r--r-- 2.0 KB
git-name-rev.txt -rw-r--r-- 1.9 KB
git-notes.txt -rw-r--r-- 13.1 KB
git-p4.txt -rw-r--r-- 18.8 KB
git-pack-objects.txt -rw-r--r-- 9.1 KB
git-pack-redundant.txt -rw-r--r-- 1.1 KB
git-pack-refs.txt -rw-r--r-- 2.0 KB
git-parse-remote.txt -rw-r--r-- 471 bytes
git-patch-id.txt -rw-r--r-- 2.1 KB
git-prune-packed.txt -rw-r--r-- 939 bytes
git-prune.txt -rw-r--r-- 1.8 KB
git-pull.txt -rw-r--r-- 8.0 KB
git-push.txt -rw-r--r-- 19.8 KB
git-quiltimport.txt -rw-r--r-- 1.4 KB
git-read-tree.txt -rw-r--r-- 16.4 KB
git-rebase.txt -rw-r--r-- 25.0 KB
git-receive-pack.txt -rw-r--r-- 7.8 KB
git-reflog.txt -rw-r--r-- 4.1 KB
git-relink.txt -rw-r--r-- 649 bytes
git-remote-ext.txt -rw-r--r-- 3.9 KB
git-remote-fd.txt -rw-r--r-- 1.6 KB
git-remote-helpers.txto -rw-r--r-- 218 bytes
git-remote-testgit.txt -rw-r--r-- 570 bytes
git-remote.txt -rw-r--r-- 7.6 KB
git-repack.txt -rw-r--r-- 5.2 KB
git-replace.txt -rw-r--r-- 4.8 KB
git-request-pull.txt -rw-r--r-- 1.9 KB
git-rerere.txt -rw-r--r-- 7.3 KB
git-reset.txt -rw-r--r-- 14.2 KB
git-rev-list.txt -rw-r--r-- 3.6 KB
git-rev-parse.txt -rw-r--r-- 13.0 KB
git-revert.txt -rw-r--r-- 3.8 KB
git-rm.txt -rw-r--r-- 6.2 KB
git-send-email.txt -rw-r--r-- 15.9 KB
git-send-pack.txt -rw-r--r-- 4.2 KB
git-sh-i18n--envsubst.txt -rw-r--r-- 928 bytes
git-sh-i18n.txt -rw-r--r-- 1.1 KB
git-sh-setup.txt -rw-r--r-- 2.9 KB
git-shell.txt -rw-r--r-- 2.5 KB
git-shortlog.txt -rw-r--r-- 2.6 KB
git-show-branch.txt -rw-r--r-- 6.4 KB
git-show-index.txt -rw-r--r-- 478 bytes
git-show-ref.txt -rw-r--r-- 5.9 KB
git-show.txt -rw-r--r-- 1.8 KB
git-stage.txt -rw-r--r-- 298 bytes
git-stash.txt -rw-r--r-- 10.3 KB
git-status.txt -rw-r--r-- 8.5 KB
git-stripspace.txt -rw-r--r-- 1.9 KB
git-submodule.txt -rw-r--r-- 17.2 KB
git-svn.txt -rw-r--r-- 42.8 KB
git-symbolic-ref.txt -rw-r--r-- 1.9 KB
git-tag.txt -rw-r--r-- 10.5 KB
git-tools.txt -rw-r--r-- 3.4 KB
git-unpack-file.txt -rw-r--r-- 434 bytes
git-unpack-objects.txt -rw-r--r-- 1.1 KB
git-update-index.txt -rw-r--r-- 13.8 KB
git-update-ref.txt -rw-r--r-- 5.3 KB
git-update-server-info.txt -rw-r--r-- 797 bytes
git-upload-archive.txt -rw-r--r-- 2.0 KB
git-upload-pack.txt -rw-r--r-- 869 bytes
git-var.txt -rw-r--r-- 1.8 KB
git-verify-commit.txt -rw-r--r-- 444 bytes
git-verify-pack.txt -rw-r--r-- 1.1 KB
git-verify-tag.txt -rw-r--r-- 411 bytes
git-web--browse.txt -rw-r--r-- 3.5 KB
git-whatchanged.txt -rw-r--r-- 1.1 KB
git-write-tree.txt -rw-r--r-- 1.0 KB
git.txt -rw-r--r-- 38.9 KB
gitattributes.txt -rw-r--r-- 33.7 KB
gitcli.txt -rw-r--r-- 7.9 KB
gitcore-tutorial.txt -rw-r--r-- 61.4 KB
gitcredentials.txt -rw-r--r-- 5.9 KB
gitcvs-migration.txt -rw-r--r-- 7.4 KB
gitdiffcore.txt -rw-r--r-- 11.4 KB
giteveryday.txt -rw-r--r-- 14.2 KB
gitglossary.txt -rw-r--r-- 359 bytes
githooks.txt -rw-r--r-- 14.9 KB
gitignore.txt -rw-r--r-- 7.1 KB
gitk.txt -rw-r--r-- 5.8 KB
gitmodules.txt -rw-r--r-- 3.8 KB
gitnamespaces.txt -rw-r--r-- 3.2 KB
gitremote-helpers.txt -rw-r--r-- 17.3 KB
gitrepository-layout.txt -rw-r--r-- 8.3 KB
gitrevisions.txt -rw-r--r-- 774 bytes
gittutorial-2.txt -rw-r--r-- 14.4 KB
gittutorial.txt -rw-r--r-- 22.4 KB
gitweb.conf.txt -rw-r--r-- 39.8 KB
gitweb.txt -rw-r--r-- 26.3 KB
gitworkflows.txt -rw-r--r-- 17.0 KB
glossary-content.txt -rw-r--r-- 25.5 KB
howto-index.sh -rwxr-xr-x 673 bytes
i18n.txt -rw-r--r-- 2.2 KB
install-doc-quick.sh -rwxr-xr-x 771 bytes
install-webdoc.sh -rwxr-xr-x 757 bytes
line-range-format.txt -rw-r--r-- 982 bytes
mailmap.txt -rw-r--r-- 2.4 KB
manpage-1.72.xsl -rw-r--r-- 510 bytes
manpage-base-url.xsl.in -rw-r--r-- 320 bytes
manpage-base.xsl -rw-r--r-- 1.2 KB
manpage-bold-literal.xsl -rw-r--r-- 578 bytes
manpage-normal.xsl -rw-r--r-- 475 bytes
manpage-quote-apos.xsl -rw-r--r-- 585 bytes
manpage-suppress-sp.xsl -rw-r--r-- 737 bytes
merge-config.txt -rw-r--r-- 3.3 KB
merge-options.txt -rw-r--r-- 3.6 KB
merge-strategies.txt -rw-r--r-- 5.1 KB
pretty-formats.txt -rw-r--r-- 8.0 KB
pretty-options.txt -rw-r--r-- 3.2 KB
pull-fetch-param.txt -rw-r--r-- 2.8 KB
rev-list-options.txt -rw-r--r-- 30.1 KB
revisions.txt -rw-r--r-- 11.9 KB
sequencer.txt -rw-r--r-- 392 bytes
urls-remotes.txt -rw-r--r-- 2.4 KB
urls.txt -rw-r--r-- 3.5 KB
user-manual.conf -rw-r--r-- 432 bytes
user-manual.txt -rw-r--r-- 170.2 KB

back to top