diff hgext/convert/git.py @ 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 ff0d3b6b287f
line wrap: on
line diff
--- 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: