-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-143010: Prevent a TOCTOU issue by only calling open once #143011
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
base: main
Are you sure you want to change the base?
Conversation
… TOCTOU issue by only calling open once We can literally just use open(path, 'xb+') for _create_carefully.
sobolevn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please start with a failing test that can show us what's wrong?
This is going to be very difficult given the fact it has to be precisely timed to the nanosecond as it is between opening of the file descriptor to the opening of the path again. |
|
By the way, this code is older than the "x" was added in 2012, which is why this wasn't used in the first place. |
|
I think that you can create a test by mocking open with a side_effect that munges things before making the real open call. Is that worth doing? |
Misc/NEWS.d/next/Library/2025-12-20-01-49-02.gh-issue-143010._-SWX0.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Misc/NEWS.d/next/Library/2025-12-20-01-49-02.gh-issue-143010._-SWX0.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: sobolevn <mail@sobolevn.me>
We can literally just use open(path, 'xb+') for _create_carefully
mailbox._create_carefullyhas a possible toctou error #143010