Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested fixes by iCR, OpenRefactory, Inc. #1486

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php

from ast import Delete
import glob
from io import BytesIO
import os
Expand Down Expand Up @@ -351,7 +352,10 @@ 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)

# OpenRefactory Warning: The method 'tempfile.mktemp' creates temporary file in an insecure way.
# use 'NamedTemporaryFile' instead of using 'mktemp' to create temporary file
tmp_index = tempfile.NamedTemporaryFile("", "", repo.git_dir).name
arg_list.append("--index-output=%s" % tmp_index)
arg_list.extend(treeish)

Expand Down
4 changes: 3 additions & 1 deletion git/index/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ 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("", "", "")
# OpenRefactory Warning: The method 'tempfile.mktemp' creates temporary file in an insecure way.
# use 'NamedTemporaryFile' instead of using 'mktemp' to create temporary file
self.tmp_file_path = str(self.file_path) + tempfile.NamedTemporaryFile("", "", "").name
# it may be that the source does not exist
try:
os.rename(self.file_path, self.tmp_file_path)
Expand Down