From a179dd36ad280d97b3ec80da1b91708a48ea4f04 Mon Sep 17 00:00:00 2001 From: ready-research <72916209+ready-research@users.noreply.github.com> Date: Fri, 29 Apr 2022 17:34:02 +0530 Subject: [PATCH 1/2] Use tempfile.mkstemp instead of tempfile.mktemp The `tempfile.mktemp` function is [deprecated](https://docs.python.org/3/library/tempfile.html#tempfile.mktemp) due to security issues. --- git/index/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/index/base.py b/git/index/base.py index 209bfa8de..503f63179 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -339,7 +339,7 @@ def from_tree(cls, repo: 'Repo', *treeish: Treeish, **kwargs: Any) -> 'IndexFile # tmp file created in git home directory to be sure renaming # works - /tmp/ dirs could be on another device - tmp_index = tempfile.mktemp('', '', repo.git_dir) + tmp_index = tempfile.mkdtemp('', '', repo.git_dir) arg_list.append("--index-output=%s" % tmp_index) arg_list.extend(treeish) From 1e14bf8f6d58a39d72c9c422364b4ee39a924e8c Mon Sep 17 00:00:00 2001 From: ready-research <72916209+ready-research@users.noreply.github.com> Date: Fri, 29 Apr 2022 17:36:58 +0530 Subject: [PATCH 2/2] Update util.py --- git/index/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/index/util.py b/git/index/util.py index 4f8af5531..91bdbef87 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -38,7 +38,7 @@ class TemporaryFileSwap(object): def __init__(self, file_path: PathLike) -> None: self.file_path = file_path - self.tmp_file_path = str(self.file_path) + tempfile.mktemp('', '', '') + self.tmp_file_path = str(self.file_path) + tempfile.mkdtemp('', '', '') # it may be that the source does not exist try: os.rename(self.file_path, self.tmp_file_path)