Bug 3581 - Arguments for external merge tools are not properly quoted
Summary: Arguments for external merge tools are not properly quoted
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-09 12:44 UTC by bh
Modified: 2012-12-22 18:56 UTC (History)
5 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bh 2012-08-09 12:44 UTC
The mercurial/filemerge.py module does not quote filenames properly when
calling external merge tools. The code in question does basically this
(revision b131e24e2984):

        args = _toolstr(ui, tool, "args", '$local $base $other')
	# ...
        args = util.interpolate(r'\$', replace, args,
                                lambda s: '"%s"' % util.localpath(s))

That is, filenames are simply surrounded by double quotes instead of
properly quoted with e.g. util.shellquote. This obviously breaks if any
of the filenames contain double quotes and can be used to inject
malicious shell code if you can trick someone who uses external merge
tools into pulling and merging from a repository with suitably chosen
filenames and changes.

There are other places in filemerge.py which use the same insufficient
quoting mechanism. For instance the toolpath with the filename of the
external tool itself is quoted in the same way.
Comment 1 Pierre-Yves David 2012-08-09 18:10 UTC
Why don't we use Popen instead of shell call ?
Comment 2 Matt Mackall 2012-08-17 16:04 UTC
> Why don't we use Popen instead of shell call ?

If your question is "why do we let users specify arbitrary shell commands rather than just executables?" the answer is "the shell is part of what makes UNIX awesome."

Seems like we need to take our existing shell quoting code and generalize it so that it can do keyword replacement like we need here and then audit all the users.
Comment 3 Matt Mackall 2012-10-19 11:57 UTC
Degrading to 'normal' - not a regression.
Comment 4 HG Bot 2012-10-31 17:58 UTC
Fixed by http://selenic.com/repo/hg/rev/9a2cf955db84
Keegan Carruthers-Smith <keegancsmith@fb.com>
filemerge: use util.shellquote when calling merge (issue3581)

(please test the fix)
Comment 5 HG Bot 2012-11-01 15:44 UTC
Fixed by http://selenic.com/repo/hg/rev/a19046744e4e
Keegan Carruthers-Smith <keegancsmith@fb.com>
filemerge: only run test for issue3581 on non-windows environments

(please test the fix)
Comment 6 HG Bot 2012-11-01 17:14 UTC
Fixed by http://selenic.com/repo/hg/rev/195ad823b5d5
Matt Mackall <mpm@selenic.com>
tests: fix test for issue3581 for vfat on Linux

(please test the fix)