Mercurial > hg
comparison mercurial/sshpeer.py @ 23671:e3f30068d2eb stable
sshpeer: more thorough shell quoting
This fixes an issue spotted by Jesse Hertz.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 29 Dec 2014 14:27:02 -0600 |
parents | ee297602a208 |
children | 14ac0c1579cd |
comparison
equal
deleted
inserted
replaced
23669:b65a01a4316b | 23671:e3f30068d2eb |
---|---|
18 def __del__(self): | 18 def __del__(self): |
19 if self.repo: | 19 if self.repo: |
20 self.release() | 20 self.release() |
21 | 21 |
22 def _serverquote(s): | 22 def _serverquote(s): |
23 if not s: | |
24 return s | |
23 '''quote a string for the remote shell ... which we assume is sh''' | 25 '''quote a string for the remote shell ... which we assume is sh''' |
24 if re.match('[a-zA-Z0-9@%_+=:,./-]*$', s): | 26 if re.match('[a-zA-Z0-9@%_+=:,./-]*$', s): |
25 return s | 27 return s |
26 return "'%s'" % s.replace("'", "'\\''") | 28 return "'%s'" % s.replace("'", "'\\''") |
27 | 29 |
43 self.path = u.path or "." | 45 self.path = u.path or "." |
44 | 46 |
45 sshcmd = self.ui.config("ui", "ssh", "ssh") | 47 sshcmd = self.ui.config("ui", "ssh", "ssh") |
46 remotecmd = self.ui.config("ui", "remotecmd", "hg") | 48 remotecmd = self.ui.config("ui", "remotecmd", "hg") |
47 | 49 |
48 args = util.sshargs(sshcmd, self.host, self.user, self.port) | 50 args = util.sshargs(sshcmd, |
51 _serverquote(self.host), | |
52 _serverquote(self.user), | |
53 _serverquote(self.port)) | |
49 | 54 |
50 if create: | 55 if create: |
51 cmd = '%s %s %s' % (sshcmd, args, | 56 cmd = '%s %s %s' % (sshcmd, args, |
52 util.shellquote("%s init %s" % | 57 util.shellquote("%s init %s" % |
53 (_serverquote(remotecmd), _serverquote(self.path)))) | 58 (_serverquote(remotecmd), _serverquote(self.path)))) |