-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
gh-122928: asserting that the tstate pointer is non-NULL using assert #122929
Conversation
I'm not totally sure this fix is necessary :( A |
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.
Adding NULL
pointer checks doesn't prevent dangling pointers.
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 |
It might be best to just turn this into an assertion |
Can I solve this by int
_PyThreadState_MustExit(PyThreadState *tstate)
{
static inline PyThreadState *
get_current_tstate(void)
{
PyThreadState *tstate = _PyThreadState_GET();
if (tstate == NULL) {
(void)check_interp(NULL);
return NULL;
}
return check_interp(tstate->interp) ? tstate : NULL;
}
PyThreadState *current_tstate = get_current_tstate();
if (current_tstate == NULL) {
return 1;
}
...
} (code from https://github.com/python/cpython/blob/main/Python/_warnings.c#L45-L45) |
No, |
I see. Finally, let's use assert(tstate! = NULL) Thank you for your review |
FWIW, I think this should be a "skip news." |
Misc/NEWS.d/next/Core_and_Builtins/2024-08-12-10-02-40.gh-issue-122928.e6_yVr.rst
Outdated
Show resolved
Hide resolved
deleted |
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.
Looks good, now we're just validating a precondition. @kumaraditya303, could you re-review?
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.
This change is wrong. There are exactly 4 calls to this function. 1 in _threadmodule.c, 3 in ceval_gil.c. All code paths check that tstate is not NULL before calling _PyThreadState_MustExit().
Moreover, I don't understand which problem you are trying to solve here. Dangling pointers cannot be avoided by checking a pointer value (NULL or anything else).
Yeah, this was originally conceived as a way to prevent dangling pointers, but there was some misunderstanding on the difference between a |
To prevent dangling pointer issues, adding a check for NULL ensures that invalid pointers are not dereferenced
This is my first time contributing to the C part of python and maybe there will be some issues