Mercurial > hg
comparison hgext/convert/git.py @ 28661:b732e7f2aba4 stable
convert: dead code removal - old git calling functions (SEC)
CVE-2016-3069 (3/5)
author | Mateusz Kwapich <mitrandir@fb.com> |
---|---|
date | Tue, 22 Mar 2016 17:05:11 -0700 |
parents | cdda7b96afff |
children | 80cac1de6aea |
comparison
equal
deleted
inserted
replaced
28660:cdda7b96afff | 28661:b732e7f2aba4 |
---|---|
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'): | 32 if util.safehasattr(os, 'unsetenv'): |
33 def gitopen(self, s, err=None): | |
34 prevgitdir = os.environ.get('GIT_DIR') | |
35 os.environ['GIT_DIR'] = self.path | |
36 try: | |
37 if err == subprocess.PIPE: | |
38 (stdin, stdout, stderr) = util.popen3(s) | |
39 return stdout | |
40 elif err == subprocess.STDOUT: | |
41 return self.popen_with_stderr(s) | |
42 else: | |
43 return util.popen(s, 'rb') | |
44 finally: | |
45 if prevgitdir is None: | |
46 del os.environ['GIT_DIR'] | |
47 else: | |
48 os.environ['GIT_DIR'] = prevgitdir | |
49 | |
50 def gitpipe(self, s): | 33 def gitpipe(self, s): |
51 prevgitdir = os.environ.get('GIT_DIR') | 34 prevgitdir = os.environ.get('GIT_DIR') |
52 os.environ['GIT_DIR'] = self.path | 35 os.environ['GIT_DIR'] = self.path |
53 try: | 36 try: |
54 return util.popen3(s) | 37 return util.popen3(s) |
57 del os.environ['GIT_DIR'] | 40 del os.environ['GIT_DIR'] |
58 else: | 41 else: |
59 os.environ['GIT_DIR'] = prevgitdir | 42 os.environ['GIT_DIR'] = prevgitdir |
60 | 43 |
61 else: | 44 else: |
62 def gitopen(self, s, err=None): | |
63 if err == subprocess.PIPE: | |
64 (sin, so, se) = util.popen3('GIT_DIR=%s %s' % (self.path, s)) | |
65 return so | |
66 elif err == subprocess.STDOUT: | |
67 return self.popen_with_stderr(s) | |
68 else: | |
69 return util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb') | |
70 | |
71 def gitpipe(self, s): | 45 def gitpipe(self, s): |
72 return util.popen3('GIT_DIR=%s %s' % (self.path, s)) | 46 return util.popen3('GIT_DIR=%s %s' % (self.path, s)) |
73 | 47 |
74 def _gitcmd(self, cmd, *args, **kwargs): | 48 def _gitcmd(self, cmd, *args, **kwargs): |
75 return cmd('--git-dir=%s' % self.path, *args, **kwargs) | 49 return cmd('--git-dir=%s' % self.path, *args, **kwargs) |
83 def gitrunlines0(self, *args, **kwargs): | 57 def gitrunlines0(self, *args, **kwargs): |
84 return self._gitcmd(self.runlines0, *args, **kwargs) | 58 return self._gitcmd(self.runlines0, *args, **kwargs) |
85 | 59 |
86 def gitrunlines(self, *args, **kwargs): | 60 def gitrunlines(self, *args, **kwargs): |
87 return self._gitcmd(self.runlines, *args, **kwargs) | 61 return self._gitcmd(self.runlines, *args, **kwargs) |
88 | |
89 def popen_with_stderr(self, s): | |
90 p = subprocess.Popen(s, shell=True, bufsize=-1, | |
91 close_fds=util.closefds, | |
92 stdin=subprocess.PIPE, | |
93 stdout=subprocess.PIPE, | |
94 stderr=subprocess.STDOUT, | |
95 universal_newlines=False, | |
96 env=None) | |
97 return p.stdout | |
98 | 62 |
99 def gitread(self, s): | 63 def gitread(self, s): |
100 fh = self.gitopen(s) | 64 fh = self.gitopen(s) |
101 data = fh.read() | 65 data = fh.read() |
102 return data, fh.close() | 66 return data, fh.close() |