comparison 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
comparison
equal deleted inserted replaced
28661:b732e7f2aba4 28662:80cac1de6aea
27 27
28 class convert_git(converter_source, commandline): 28 class convert_git(converter_source, commandline):
29 # Windows does not support GIT_DIR= construct while other systems 29 # Windows does not support GIT_DIR= construct while other systems
30 # cannot remove environment variable. Just assume none have 30 # cannot remove environment variable. Just assume none have
31 # both issues. 31 # both issues.
32 if util.safehasattr(os, 'unsetenv'):
33 def gitpipe(self, s):
34 prevgitdir = os.environ.get('GIT_DIR')
35 os.environ['GIT_DIR'] = self.path
36 try:
37 return util.popen3(s)
38 finally:
39 if prevgitdir is None:
40 del os.environ['GIT_DIR']
41 else:
42 os.environ['GIT_DIR'] = prevgitdir
43
44 else:
45 def gitpipe(self, s):
46 return util.popen3('GIT_DIR=%s %s' % (self.path, s))
47 32
48 def _gitcmd(self, cmd, *args, **kwargs): 33 def _gitcmd(self, cmd, *args, **kwargs):
49 return cmd('--git-dir=%s' % self.path, *args, **kwargs) 34 return cmd('--git-dir=%s' % self.path, *args, **kwargs)
50 35
51 def gitrun0(self, *args, **kwargs): 36 def gitrun0(self, *args, **kwargs):
57 def gitrunlines0(self, *args, **kwargs): 42 def gitrunlines0(self, *args, **kwargs):
58 return self._gitcmd(self.runlines0, *args, **kwargs) 43 return self._gitcmd(self.runlines0, *args, **kwargs)
59 44
60 def gitrunlines(self, *args, **kwargs): 45 def gitrunlines(self, *args, **kwargs):
61 return self._gitcmd(self.runlines, *args, **kwargs) 46 return self._gitcmd(self.runlines, *args, **kwargs)
47
48 def gitpipe(self, *args, **kwargs):
49 return self._gitcmd(self._run3, *args, **kwargs)
62 50
63 def gitread(self, s): 51 def gitread(self, s):
64 fh = self.gitopen(s) 52 fh = self.gitopen(s)
65 data = fh.read() 53 data = fh.read()
66 return data, fh.close() 54 return data, fh.close()
90 checktool('git', 'git') 78 checktool('git', 'git')
91 79
92 self.path = path 80 self.path = path
93 self.submodules = [] 81 self.submodules = []
94 82
95 self.catfilepipe = self.gitpipe('git cat-file --batch') 83 self.catfilepipe = self.gitpipe('cat-file', '--batch')
96 84
97 def after(self): 85 def after(self):
98 for f in self.catfilepipe: 86 for f in self.catfilepipe:
99 f.close() 87 f.close()
100 88