changeset 28662:80cac1de6aea stable

convert: rewrite gitpipe to use common.commandline (SEC) CVE-2016-3069 (4/5)
author Mateusz Kwapich <mitrandir@fb.com>
date Tue, 22 Mar 2016 17:05:11 -0700
parents b732e7f2aba4
children ae279d4a19e9
files hgext/convert/common.py hgext/convert/git.py
diffstat 2 files changed, 7 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Tue Mar 22 17:05:11 2016 -0700
+++ b/hgext/convert/common.py	Tue Mar 22 17:05:11 2016 -0700
@@ -341,6 +341,9 @@
     def _run2(self, cmd, *args, **kwargs):
         return self._dorun(util.popen2, cmd, *args, **kwargs)
 
+    def _run3(self, cmd, *args, **kwargs):
+        return self._dorun(util.popen3, cmd, *args, **kwargs)
+
     def _dorun(self, openfunc, cmd,  *args, **kwargs):
         cmdline = self._cmdline(cmd, *args, **kwargs)
         self.ui.debug('running: %s\n' % (cmdline,))
--- a/hgext/convert/git.py	Tue Mar 22 17:05:11 2016 -0700
+++ b/hgext/convert/git.py	Tue Mar 22 17:05:11 2016 -0700
@@ -29,21 +29,6 @@
     # Windows does not support GIT_DIR= construct while other systems
     # cannot remove environment variable. Just assume none have
     # both issues.
-    if util.safehasattr(os, 'unsetenv'):
-        def gitpipe(self, s):
-            prevgitdir = os.environ.get('GIT_DIR')
-            os.environ['GIT_DIR'] = self.path
-            try:
-                return util.popen3(s)
-            finally:
-                if prevgitdir is None:
-                    del os.environ['GIT_DIR']
-                else:
-                    os.environ['GIT_DIR'] = prevgitdir
-
-    else:
-        def gitpipe(self, s):
-            return util.popen3('GIT_DIR=%s %s' % (self.path, s))
 
     def _gitcmd(self, cmd, *args, **kwargs):
         return cmd('--git-dir=%s' % self.path, *args, **kwargs)
@@ -60,6 +45,9 @@
     def gitrunlines(self, *args, **kwargs):
         return self._gitcmd(self.runlines, *args, **kwargs)
 
+    def gitpipe(self, *args, **kwargs):
+        return self._gitcmd(self._run3, *args, **kwargs)
+
     def gitread(self, s):
         fh = self.gitopen(s)
         data = fh.read()
@@ -92,7 +80,7 @@
         self.path = path
         self.submodules = []
 
-        self.catfilepipe = self.gitpipe('git cat-file --batch')
+        self.catfilepipe = self.gitpipe('cat-file', '--batch')
 
     def after(self):
         for f in self.catfilepipe: