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

Avoid TOCTOU errors in cache initialization #10884

Merged
merged 1 commit into from
Apr 11, 2024
Merged

Avoid TOCTOU errors in cache initialization #10884

merged 1 commit into from
Apr 11, 2024

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Apr 11, 2024

Summary

I believe this should close #10880? The .gitignore creation seems ok, since it truncates, but using cachedir::is_tagged followed by cachedir::add_tag is not safe, as cachedir::add_tag fails if the file already exists.

This also matches the structure of the code in uv.

Closes #10880.

@charliermarsh charliermarsh added the bug Something isn't working label Apr 11, 2024
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 1 projects; 43 projects unchanged)

pandas-dev/pandas (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ scripts/validate_unwanted_patterns.py:428:3: E999 SyntaxError: unindent does not match any outer indentation level

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
E999 1 1 0 0 0

@charliermarsh charliermarsh merged commit 0cc154c into main Apr 11, 2024
17 checks passed
@charliermarsh charliermarsh deleted the charlie/git branch April 11, 2024 16:09
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request Apr 12, 2024
## Summary

I believe this should close
astral-sh#10880? The `.gitignore`
creation seems ok, since it truncates, but using `cachedir::is_tagged`
followed by `cachedir::add_tag` is not safe, as `cachedir::add_tag`
_fails_ if the file already exists.

This also matches the structure of the code in `uv`.

Closes astral-sh#10880.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error: Failed to initialize cache at <dir>/.ruff_cache: File exists (os error 17)
2 participants