Skip to content

Commit 1c65efb

Browse files
committed
Show "not from cwd" test is broken for shell=True
This adds a test_it_executes_git_not_from_cwd case for shell=True. (This case also gives the command as a string, so the test need not be further special-cased for non-Windows systems, where argument lists aren't accepted with shell=True.) The test did not attempt to cover the shell=True case before, because I had erroneously assumed it worked similarity. It is actually very different, because when a shell is used, both the shell and the command the shell runs must be found and executed, and because the process creation GitPython performs is that of the shell process, with the state of the shell process being what is relevant to how the path search is done for the git (or other) command. The code change here does not itself demonstrate that the test is broken for shell=True, because that case passes. However, manually undoing the fix in cmd.py for CVE-2023-40590, which as expected causes the preexisting (implicitly shell=False case) to fail, does *not* cause the new shell=True case to fail. That case passes! That passing result in the absence of a fix for CVE-2023-40590 is erroneous, because the cmd.exe shell does search the CWD first when nothing has been done to prevent it.
1 parent 32c02d1 commit 1c65efb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/test_git.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ def test_it_logs_istream_summary_for_stdin(self, case):
134134
def test_it_executes_git_and_returns_result(self):
135135
self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$")
136136

137-
def test_it_executes_git_not_from_cwd(self):
137+
@ddt.data(
138+
(["git", "version"], False),
139+
("git version", True),
140+
)
141+
def test_it_executes_git_not_from_cwd(self, case):
142+
command, shell = case
143+
138144
with TemporaryDirectory() as tmpdir:
139145
if os.name == "nt":
140146
# Copy an actual binary executable that is not git.
@@ -149,7 +155,9 @@ def test_it_executes_git_not_from_cwd(self):
149155
os.chmod(impostor_path, 0o755)
150156

151157
with cwd(tmpdir):
152-
self.assertRegex(self.git.execute(["git", "version"]), r"^git version\b")
158+
output = self.git.execute(command, shell=shell)
159+
160+
self.assertRegex(output, r"^git version\b")
153161

154162
@skipUnless(
155163
os.name == "nt",

0 commit comments

Comments
 (0)