diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -23,6 +23,7 @@ import unicodedata from .i18n import _ from . import ( encoding, + error, pycompat, ) @@ -91,6 +92,9 @@ def parsepatchoutput(output_line): def sshargs(sshcmd, host, user, port): '''Build argument list for ssh''' args = user and ("%s@%s" % (user, host)) or host + if '-' in args[:2]: + raise error.Abort( + _('illegal ssh hostname or username starting with -: %s') % args) return port and ("%s -p %s" % (args, port)) or args def isexec(f): diff --git a/mercurial/windows.py b/mercurial/windows.py --- a/mercurial/windows.py +++ b/mercurial/windows.py @@ -17,6 +17,7 @@ import sys from .i18n import _ from . import ( encoding, + error, policy, pycompat, win32, @@ -203,6 +204,10 @@ def sshargs(sshcmd, host, user, port): '''Build argument list for ssh or Plink''' pflag = 'plink' in sshcmd.lower() and '-P' or '-p' args = user and ("%s@%s" % (user, host)) or host + if args.startswith('-') or args.startswith('/'): + raise error.Abort( + _('illegal ssh hostname or username starting with - or /: %s') % + args) return port and ("%s %s %s" % (args, pflag, port)) or args def setflags(f, l, x):