-
-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1636 from EliahKagan/cve-2023-40590
Fix CVE-2023-40590
- Loading branch information
Showing
2 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ | |
# | ||
# This module is part of GitPython and is released under | ||
# the BSD License: http://www.opensource.org/licenses/bsd-license.php | ||
import contextlib | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
from tempfile import TemporaryFile | ||
from tempfile import TemporaryDirectory, TemporaryFile | ||
from unittest import mock | ||
|
||
from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd | ||
|
@@ -20,6 +22,17 @@ | |
from git.compat import is_win | ||
|
||
|
||
@contextlib.contextmanager | ||
def _chdir(new_dir): | ||
"""Context manager to temporarily change directory. Not reentrant.""" | ||
old_dir = os.getcwd() | ||
os.chdir(new_dir) | ||
try: | ||
yield | ||
finally: | ||
os.chdir(old_dir) | ||
|
||
|
||
class TestGit(TestBase): | ||
@classmethod | ||
def setUpClass(cls): | ||
|
@@ -75,6 +88,23 @@ def test_it_transforms_kwargs_into_git_command_arguments(self): | |
def test_it_executes_git_to_shell_and_returns_result(self): | ||
self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$") | ||
|
||
def test_it_executes_git_not_from_cwd(self): | ||
with TemporaryDirectory() as tmpdir: | ||
if is_win: | ||
# Copy an actual binary executable that is not git. | ||
other_exe_path = os.path.join(os.getenv("WINDIR"), "system32", "hostname.exe") | ||
impostor_path = os.path.join(tmpdir, "git.exe") | ||
shutil.copy(other_exe_path, impostor_path) | ||
else: | ||
# Create a shell script that doesn't do anything. | ||
impostor_path = os.path.join(tmpdir, "git") | ||
with open(impostor_path, mode="w", encoding="utf-8") as file: | ||
print("#!/bin/sh", file=file) | ||
os.chmod(impostor_path, 0o755) | ||
|
||
with _chdir(tmpdir): | ||
self.assertRegex(self.git.execute(["git", "version"]), r"^git version\b") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Byron
Author
Member
|
||
|
||
def test_it_accepts_stdin(self): | ||
filename = fixture_path("cat_file_blob") | ||
with open(filename, "r") as fh: | ||
|
So if the imposter binary supports a version sub-command and returns a string beginning with "git version", it would be considered safe?