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

Security3 #10944

Merged
merged 3 commits into from
Feb 9, 2023
Merged

Security3 #10944

merged 3 commits into from
Feb 9, 2023

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Feb 9, 2023

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Upgraded system calls to subprocess module for better security and compliance.

πŸ“Š Key Changes

  • Replaced os.system calls with subprocess.run in files such as train.py, val.py, and downloads.py.
  • Importing subprocess module in files where system calls have been replaced.

🎯 Purpose & Impact

  • πŸ›‘οΈ Enhanced Security: Using subprocess prevents shell injection vulnerabilities that can occur with os.system.
  • πŸ”§ Improved Error Handling: subprocess allows better handling of exceptions and program output.
  • βœ”οΈ User Trust: Ensures the codebase follows best practices, inspiring confidence and trust among users and developers.

@glenn-jocher glenn-jocher merged commit 238da32 into master Feb 9, 2023
@glenn-jocher glenn-jocher deleted the security3 branch February 9, 2023 13:58
Copy link
Contributor

@akx akx left a comment

Choose a reason for hiding this comment

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

I don't think these changes make things any more secure; in fact, they will probably break things.

@@ -597,7 +598,8 @@ def main(opt, callbacks=Callbacks()):
# ei = [isinstance(x, (int, float)) for x in hyp.values()] # evolvable indices
evolve_yaml, evolve_csv = save_dir / 'hyp_evolve.yaml', save_dir / 'evolve.csv'
if opt.bucket:
os.system(f'gsutil cp gs://{opt.bucket}/evolve.csv {evolve_csv}') # download evolve.csv if exists
subprocess.run(
f'gsutil cp gs://{opt.bucket}/evolve.csv {evolve_csv}'.split()) # download evolve.csv if exists
Copy link
Contributor

Choose a reason for hiding this comment

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

This will break if the bucket name or filename contains a space.

(This repeats for the other gsutil incantation.)

@@ -461,7 +462,7 @@ def main(opt):
r, _, t = run(**vars(opt), plots=False)
y.append(r + t) # results and times
np.savetxt(f, y, fmt='%10.4g') # save
os.system('zip -r study.zip study_*.txt')
subprocess.run('zip -r study.zip study_*.txt'.split())
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this change really makes anything more secure.

(This repeats for the other zip.)

@@ -50,7 +50,8 @@ def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''):
if file.exists():
file.unlink() # remove partial downloads
LOGGER.info(f'ERROR: {e}\nRe-attempting {url2 or url} to {file}...')
os.system(f"curl -# -L '{url2 or url}' -o '{file}' --retry 3 -C -") # curl download, retry and resume on fail
subprocess.run(
f"curl -# -L '{url2 or url}' -o '{file}' --retry 3 -C -".split()) # curl download, retry and resume on fail
Copy link
Contributor

Choose a reason for hiding this comment

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

Same space-brokenness here, not to mention there will now be quotes in the split arguments that wouldn't be there otherwise. (This repeats for the other curl.)

akx added a commit to akx/yolov5 that referenced this pull request Feb 13, 2023
Subprocess.run does not return an integer.

Regressed in ultralytics#10944
akx added a commit to akx/yolov5 that referenced this pull request Feb 13, 2023
akx added a commit to akx/yolov5 that referenced this pull request Feb 13, 2023
@akx akx mentioned this pull request Feb 13, 2023
akx added a commit to akx/yolov5 that referenced this pull request Feb 13, 2023
glenn-jocher pushed a commit that referenced this pull request Feb 13, 2023
Subprocess.run does not return an integer.

Regressed in #10944
glenn-jocher added a commit that referenced this pull request Feb 13, 2023
* Use list-form arguments for subprocess.run calls where possible

Augments #10944

* Deduplicate curl code

* Avoid eval() to parse integer

---------

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Smfun12 pushed a commit to Smfun12/yolov5 that referenced this pull request Mar 24, 2023
* Security improvements

* Security improvements

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Smfun12 pushed a commit to Smfun12/yolov5 that referenced this pull request Mar 24, 2023
Subprocess.run does not return an integer.

Regressed in ultralytics#10944
Smfun12 pushed a commit to Smfun12/yolov5 that referenced this pull request Mar 24, 2023
* Use list-form arguments for subprocess.run calls where possible

Augments ultralytics#10944

* Deduplicate curl code

* Avoid eval() to parse integer

---------

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
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