8000 bpo-45826: Fix a crash in suggestions.c by checking for `traceback is None` by sweeneyde · Pull Request #29590 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45826: Fix a crash in suggestions.c by checking for traceback is None #29590

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

Merged
merged 5 commits into from
Nov 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check for wrong type, not just for None
  • Loading branch information
sweeneyde committed Nov 17, 2021
commit 04a4ebb1f8300309680d8d723c0a5d632391716e
5 changes: 2 additions & 3 deletions Python/suggestions.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,15 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
// 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 || !PyUnicode_CheckExact(name) ||
Copy link
Member
@pablogsal pablogsal Nov 17, 2021

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

Copy link
Member Author

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.

traceback == NULL || Py_IsNone((PyObject *)traceback)
traceback == NULL || !Py_IS_TYPE(traceback, &PyTraceBack_Type)
) {
return NULL;
}

// Move to the traceback of the exception
while (1) {
assert(Py_IS_TYPE(traceback, &PyTraceBack_Type));
PyTracebackObject *next = traceback->tb_next;
if (next == NULL || Py_IsNone((PyObject *)traceback)) {
if (next == NULL || !Py_IS_TYPE(next, &PyTraceBack_Type)) {
break;
}
else {
Expand Down
0