-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
bpo-45826: Fix a crash in suggestions.c by checking for traceback is None
#29590
Conversation
@@ -202,13 +202,22 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) | |||
PyTracebackObject *traceback = (PyTracebackObject *) exc->traceback; // borrowed reference | |||
// Abort if we don't have a variable name or we have an invalid one | |||
// or if we don't have a traceback to work with | |||
if (name == NULL || traceback == NULL || !PyUnicode_CheckExact(name)) { | |||
if (name == NULL || !PyUnicode_CheckExact(name) || |
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.
Instead of checking for None, we can check if the traceback object parent class is the traceback type (.PyTraceBack_Type) . This way we also stop segfaults if someone placed any other object there
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.
Isn't tb_next is supposed to be None or a Traceback? Regardless, I agree that it is more clear to just check for type.
Thanks @sweeneyde for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry @sweeneyde and @ambv, I had trouble checking out the |
…back is None` (pythonGH-29590) (cherry picked from commit 5d90c46) Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
GH-29602 is a backport of this pull request to the 3.10 branch. |
https://bugs.python.org/issue45826