##// END OF EJS Templates
ssh: quote parameters using shellquote (SEC)...
Jun Wu -
r33732:8cb9e921 stable
parent child Browse files
Show More
@@ -92,10 +92,13 b' def parsepatchoutput(output_line):'
92 def sshargs(sshcmd, host, user, port):
92 def sshargs(sshcmd, host, user, port):
93 '''Build argument list for ssh'''
93 '''Build argument list for ssh'''
94 args = user and ("%s@%s" % (user, host)) or host
94 args = user and ("%s@%s" % (user, host)) or host
95 if '-' in args[:2]:
95 if '-' in args[:1]:
96 raise error.Abort(
96 raise error.Abort(
97 _('illegal ssh hostname or username starting with -: %s') % args)
97 _('illegal ssh hostname or username starting with -: %s') % args)
98 return port and ("%s -p %s" % (args, port)) or args
98 args = shellquote(args)
99 if port:
100 args = '-p %s %s' % (shellquote(port), args)
101 return args
99
102
100 def isexec(f):
103 def isexec(f):
101 """check whether a file is executable"""
104 """check whether a file is executable"""
@@ -151,10 +151,7 b' class sshpeer(wireproto.wirepeer):'
151 sshcmd = self.ui.config("ui", "ssh")
151 sshcmd = self.ui.config("ui", "ssh")
152 remotecmd = self.ui.config("ui", "remotecmd")
152 remotecmd = self.ui.config("ui", "remotecmd")
153
153
154 args = util.sshargs(sshcmd,
154 args = util.sshargs(sshcmd, self.host, self.user, self.port)
155 _serverquote(self.host),
156 _serverquote(self.user),
157 _serverquote(self.port))
158
155
159 if create:
156 if create:
160 cmd = '%s %s %s' % (sshcmd, args,
157 cmd = '%s %s %s' % (sshcmd, args,
@@ -208,7 +208,10 b' def sshargs(sshcmd, host, user, port):'
208 raise error.Abort(
208 raise error.Abort(
209 _('illegal ssh hostname or username starting with - or /: %s') %
209 _('illegal ssh hostname or username starting with - or /: %s') %
210 args)
210 args)
211 return port and ("%s %s %s" % (args, pflag, port)) or args
211 args = shellquote(args)
212 if port:
213 args = '%s %s %s' % (pflag, shellquote(port), args)
214 return args
212
215
213 def setflags(f, l, x):
216 def setflags(f, l, x):
214 pass
217 pass
@@ -1100,6 +1100,11 b' pooled".'
1100
1100
1101 SEC: check for unsafe ssh url
1101 SEC: check for unsafe ssh url
1102
1102
1103 $ cat >> $HGRCPATH << EOF
1104 > [ui]
1105 > ssh = sh -c "read l; read l; read l"
1106 > EOF
1107
1103 $ hg clone 'ssh://-oProxyCommand=touch${IFS}owned/path'
1108 $ hg clone 'ssh://-oProxyCommand=touch${IFS}owned/path'
1104 abort: potentially unsafe url: 'ssh://-oProxyCommand=touch${IFS}owned/path'
1109 abort: potentially unsafe url: 'ssh://-oProxyCommand=touch${IFS}owned/path'
1105 [255]
1110 [255]
@@ -1116,6 +1121,42 b' SEC: check for unsafe ssh url'
1116 $ hg clone 'ssh://-oProxyCommand=touch owned%20foo@example.com/nonexistent/path'
1121 $ hg clone 'ssh://-oProxyCommand=touch owned%20foo@example.com/nonexistent/path'
1117 abort: potentially unsafe url: 'ssh://-oProxyCommand=touch owned foo@example.com/nonexistent/path'
1122 abort: potentially unsafe url: 'ssh://-oProxyCommand=touch owned foo@example.com/nonexistent/path'
1118 [255]
1123 [255]
1124
1125 #if windows
1126 $ hg clone "ssh://%26touch%20owned%20/" --debug
1127 running sh -c "read l; read l; read l" "&touch owned " "hg -R . serve --stdio"
1128 sending hello command
1129 sending between command
1130 abort: no suitable response from remote hg!
1131 [255]
1132 $ hg clone "ssh://example.com:%26touch%20owned%20/" --debug
1133 running sh -c "read l; read l; read l" -p "&touch owned " example.com "hg -R . serve --stdio"
1134 sending hello command
1135 sending between command
1136 abort: no suitable response from remote hg!
1137 [255]
1138 #else
1139 $ hg clone "ssh://%3btouch%20owned%20/" --debug
1140 running sh -c "read l; read l; read l" ';touch owned ' 'hg -R . serve --stdio'
1141 sending hello command
1142 sending between command
1143 abort: no suitable response from remote hg!
1144 [255]
1145 $ hg clone "ssh://example.com:%3btouch%20owned%20/" --debug
1146 running sh -c "read l; read l; read l" -p ';touch owned ' example.com 'hg -R . serve --stdio'
1147 sending hello command
1148 sending between command
1149 abort: no suitable response from remote hg!
1150 [255]
1151 #endif
1152
1153 $ hg clone "ssh://v-alid.example.com/" --debug
1154 running sh -c "read l; read l; read l" v-alid\.example\.com ['"]hg -R \. serve --stdio['"] (re)
1155 sending hello command
1156 sending between command
1157 abort: no suitable response from remote hg!
1158 [255]
1159
1119 We should not have created a file named owned - if it exists, the
1160 We should not have created a file named owned - if it exists, the
1120 attack succeeded.
1161 attack succeeded.
1121 $ if test -f owned; then echo 'you got owned'; fi
1162 $ if test -f owned; then echo 'you got owned'; fi
@@ -461,7 +461,7 b' debug output'
461
461
462 $ hg pull --debug ssh://user@dummy/remote
462 $ hg pull --debug ssh://user@dummy/remote
463 pulling from ssh://user@dummy/remote
463 pulling from ssh://user@dummy/remote
464 running .* ".*/dummyssh" user@dummy ('|")hg -R remote serve --stdio('|") (re)
464 running .* ".*/dummyssh" ['"]user@dummy['"] ('|")hg -R remote serve --stdio('|") (re)
465 sending hello command
465 sending hello command
466 sending between command
466 sending between command
467 remote: 355
467 remote: 355
@@ -477,7 +477,7 b' debug output'
477
477
478 $ hg pull --debug ssh://user@dummy/remote
478 $ hg pull --debug ssh://user@dummy/remote
479 pulling from ssh://user@dummy/remote
479 pulling from ssh://user@dummy/remote
480 running .* ".*/dummyssh" user@dummy ('|")hg -R remote serve --stdio('|") (re)
480 running .* ".*/dummyssh" ['"]user@dummy['"] ('|")hg -R remote serve --stdio('|") (re)
481 sending hello command
481 sending hello command
482 sending between command
482 sending between command
483 remote: 355
483 remote: 355
General Comments 0
You need to be logged in to leave comments. Login now