Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 251dcef

Browse files
committed
Unfinished changes
1 parent eb4083e commit 251dcef

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

git/repo/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def _clone(cls, git, url, path, odb_default_type, progress, multi_options=None,
956956
multi = None
957957
if multi_options:
958958
multi = ' '.join(multi_options).split(' ')
959-
proc = git.clone(multi, Git.polish_url(url), clone_path, with_extended_output=True, as_process=True,
959+
proc = git.clone(multi, "--", Git.polish_url(url), clone_path, with_extended_output=True, as_process=True,
960960
v=True, universal_newlines=True, **add_progress(kwargs, git, progress))
961961
if progress:
962962
handle_process_output(proc, None, progress.new_message_handler(), finalize_process, decode_streams=False)
@@ -1044,7 +1044,7 @@ def archive(self, ostream, treeish=None, prefix=None, **kwargs):
10441044
path = [path]
10451045
# end assure paths is list
10461046

1047-
self.git.archive(treeish, *path, **kwargs)
1047+
self.git.archive("--", treeish, *path, **kwargs)
10481048
return self
10491049

10501050
def has_separate_working_tree(self):

git/test/test_repo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,24 @@ def test_git_work_tree_env(self, rw_dir):
10231023
self.assertEqual(r.working_dir, repo_dir)
10241024
finally:
10251025
os.environ = oldenv
1026+
1027+
@with_rw_repo("HEAD")
1028+
def test_clone_command_injection(self, rw_repo):
1029+
tmp_dir = pathlib.Path(tempfile.mkdtemp())
1030+
unexpected_file = tmp_dir / "pwn"
1031+
assert not unexpected_file.exists()
1032+
payload = f"--upload-pack=touch {unexpected_file}"
1033+
rw_repo.clone(payload)
1034+
assert not unexpected_file.exists()
1035+
# A repo was cloned with the payload as name
1036+
assert pathlib.Path(payload).exists()
1037+
@with_rw_repo("HEAD")
1038+
def test_clone_from_command_injection(self, rw_repo):
1039+
tmp_dir = pathlib.Path(tempfile.mkdtemp())
1040+
temp_repo = Repo.init(tmp_dir / "repo")
1041+
unexpected_file = tmp_dir / "pwn"
1042+
assert not unexpected_file.exists()
1043+
payload = f"--upload-pack=touch {unexpected_file}"
1044+
with self.assertRaises(GitCommandError):
1045+
rw_repo.clone_from(payload, temp_repo.common_dir)
1046+
assert not unexpected_file.exists()

0 commit comments

Comments
 (0)