File CVE-2017-1000116-0003.patch of Package mercurial.openSUSE_Leap_42.2_Update

# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1501869603 14400
#      Fri Aug 04 14:00:03 2017 -0400
# Branch stable
# Node ID e10745311406a9c6d2938583028ee2aaf74dd2bd
# Parent  53224b1ffbc2438941e8e50375f532f2603c8f0f
ssh: ban any username@host or host that starts with - (SEC)

This paranoia probably isn't required, but it can't hurt either.

---
 mercurial/posix.py   |    4 ++++
 mercurial/windows.py |    5 +++++
 2 files changed, 9 insertions(+)

--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -23,6 +23,7 @@ import unicodedata
 from .i18n import _
 from . import (
     encoding,
+    error,
 )
 
 posixfile = open
@@ -90,6 +91,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):
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -18,6 +18,7 @@ import sys
 from .i18n import _
 from . import (
     encoding,
+    error,
     osutil,
     win32,
 )
@@ -190,6 +191,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):
openSUSE Build Service is sponsored by