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

Remove insecure tempfile.mktemp #2677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChillerDragon
Copy link
Contributor

@ChillerDragon ChillerDragon commented Jul 30, 2020

Found by lgtm.com mentioned by @jxsl13 :)

tempfile.mktemp is deprecated since Python 2.3 and considered weak https://cwe.mitre.org/data/definitions/377.html

change is untested

Sadly I could not get all dependencies building (planetbeing/libdmg-hfsplus#14) and thus could not test this branch of code. If one has the binaries for hfsplus please test this.

As far as I understood this script should be run like this:

bam
python3 scripts/dmg.py create build/x86_64/debug test . --hdiutil <dmg path> <hfsplus path> <newfs_hfs path>

@@ -54,7 +54,7 @@ def _finish(self, hfs, dmg):
def create(self, dmg, volume_name, directory, symlinks):
input_size = sum(os.stat(os.path.join(path, f)).st_size for path, dirs, files in os.walk(directory) for f in files)
output_size = max(input_size * 2, 1024**2)
hfs = tempfile.mktemp(prefix=dmg + '.', suffix='.hfs')
hfs = NamedTemporaryFile(prefix=dmg + '.', suffix='.hfs', delete=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to have other semantics, mktemp does not create a file, NamedTemporaryFile does. This absolutely needs to be tested before merging.

This could perhaps be solved by doing the whole thing in a temporary directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants