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

Fixed Improper Method Call: Replaced mktemp #7534

Open
wants to merge 4 commits into
base: maint
Choose a base branch
from

Conversation

fazledyn-or
Copy link

Details

While triaging your project, our bug fixing tool generated the following message(s)-

In file: archives.py, there is a method that creates a temporary file using an unsafe API mktemp. The use of this method is discouraged in the Python documentation. iCR suggested that a temporary file should be created using mkstemp which is a safe API. iCR replaced the usage of mktemp with mkstemp.

In file: utils.py, there is a method that creates a temporary file using an unsafe API mktemp. The use of this method is discouraged in the Python documentation. iCR suggested that a temporary file should be created using mkstemp which is a safe API. iCR replaced the usage of mktemp with mkstemp.

Changes

  • Replaced mktemp() method with mkstemp()

Previously Found & Fixed

CLA Requirements

This section is only relevant if your project requires contributors to sign a Contributor License Agreement (CLA) for external contributions.

All contributed commits are already automatically signed off.

The meaning of a signoff depends on the project, but it typically certifies that committer has the rights to submit this work under the same license and agrees to a Developer Certificate of Origin (see https://developercertificate.org/ for more information).
- Git Commit SignOff documentation

Sponsorship and Support

This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed – to improve global software supply chain security.

The bug is found by running the Intelligent Code Repair (iCR) tool by OpenRefactory and then manually triaging the results.


CHANGELOG-missing

@yarikoptic
Copy link
Member

appveyor isn't happy with flood of fails like

FAILED ../datalad/core/distributed/tests/test_clone.py::test_install_source_relpath - NotADirectoryError: [Errno 20] Not a directory: PosixPath('/home/appveyor/DLTMP/datalad_temp_test_install_source_relpathfb488y_s')
FAILED ../datalad/core/distributed/tests/test_clone.py::test_clone_isnt_a_smartass - NotADirectoryError: [Errno 20] Not a directory: PosixPath('/home/appveyor/DLTMP/datalad_temp_test_clone_isnt_a_smartass9fe1x4l4')
FAILED ../datalad/core/distributed/tests/test_clone.py::test_autoenabled_remote_msg - NotADirectoryError: [Errno 20] Not a directory: '/home/appveyor/DLTMP/datalad_temp_test_autoenabled_remote_msg5p16gvzf'
FAILED ../datalad/core/distributed/tests/test_clone.py::test_relative_submodule_url - NotADirectoryError: [Errno 20] Not a directory: 

suggesting that 2nd portion of the patch is to blame... didn't look in detail

@yarikoptic yarikoptic added the CHANGELOG-missing When a PR's description does not contain a changelog item, yet. label Nov 8, 2023
@fazledyn-or
Copy link
Author

appveyor isn't happy with flood of fails like

FAILED ../datalad/core/distributed/tests/test_clone.py::test_install_source_relpath - NotADirectoryError: [Errno 20] Not a directory: PosixPath('/home/appveyor/DLTMP/datalad_temp_test_install_source_relpathfb488y_s')
FAILED ../datalad/core/distributed/tests/test_clone.py::test_clone_isnt_a_smartass - NotADirectoryError: [Errno 20] Not a directory: PosixPath('/home/appveyor/DLTMP/datalad_temp_test_clone_isnt_a_smartass9fe1x4l4')
FAILED ../datalad/core/distributed/tests/test_clone.py::test_autoenabled_remote_msg - NotADirectoryError: [Errno 20] Not a directory: '/home/appveyor/DLTMP/datalad_temp_test_autoenabled_remote_msg5p16gvzf'
FAILED ../datalad/core/distributed/tests/test_clone.py::test_relative_submodule_url - NotADirectoryError: [Errno 20] Not a directory: 

suggesting that 2nd portion of the patch is to blame... didn't look in detail

Looking into it.

Signed-off-by: fazledyn-or <ataf@openrefactory.com>
Signed-off-by: fazledyn-or <ataf@openrefactory.com>
@github-actions github-actions bot removed the CHANGELOG-missing When a PR's description does not contain a changelog item, yet. label Nov 9, 2023
@yarikoptic yarikoptic added the semver-patch Increment the patch version when merged label Nov 9, 2023
@@ -259,7 +259,8 @@ def __init__(self, archive, path=None, persistent=False):
self._archive = archive
# TODO: bad location for extracted archive -- use tempfile
if not path:
path = tempfile.mktemp(**get_tempfile_kwargs(prefix=_get_cached_filename(archive)))
fd, path = tempfile.mkstemp(**get_tempfile_kwargs(prefix=_get_cached_filename(archive)))
os.close(fd)
Copy link
Member

Choose a reason for hiding this comment

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

more fails remain e.g.

FAILED ../datalad/tests/test_archives.py::test_ExtractedArchive - RuntimeError: Directory /home/appveyor/DLTMP/datalad_temp_e319196a26_htmijjms already exists whenever it should not persist

so there seems to be some side effect remaining... it seems that we need to fixup code... seems can't do suggestion on lines not modified by PR but I think it should be sufficient to bring if below to be elif since it makes sense only for cases when path is not specified.

Copy link
Author

Choose a reason for hiding this comment

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

  1. I'm wondering if self.path and self._path are meant to be the same thing in datalad/support/archives.py. Because I'm not seeing any code that stores value to self.path. If it's a typo, then we can refactor the codebase to work with proposed mkstemp() method.

  2. The RunTimeError is taking place due to the implementation at line 265. It's not related to tests or anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch Increment the patch version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants