summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2021-11-17 23:03:52 (GMT)
committerGitHub <noreply@github.com>2021-11-17 23:03:52 (GMT)
commit5d90c467c02ffefdb13c1abc83a171db1a99ffad (patch)
treebb239747cec3197e1bcb47579bb6f7704952b445 /Python
parent736684b1bb67369a2e95a9f621752deead44e7ef (diff)
downloadcpython-5d90c467c02ffefdb13c1abc83a171db1a99ffad.zip
cpython-5d90c467c02ffefdb13c1abc83a171db1a99ffad.tar.gz
cpython-5d90c467c02ffefdb13c1abc83a171db1a99ffad.tar.bz2
bpo-45826: Fix a crash in suggestions.c by checking for `traceback is None` (GH-29590)
Diffstat (limited to 'Python')
-rw-r--r--Python/suggestions.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Python/suggestions.c b/Python/suggestions.c
index 81976ff..d9e69fa 100644
--- a/Python/suggestions.c
+++ b/Python/suggestions.c
@@ -202,13 +202,21 @@ 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) ||
+ traceback == NULL || !Py_IS_TYPE(traceback, &PyTraceBack_Type)
+ ) {
return NULL;
}
// Move to the traceback of the exception
- while (traceback->tb_next != NULL) {
- traceback = traceback->tb_next;
+ while (1) {
+ PyTracebackObject *next = traceback->tb_next;
+ if (next == NULL || !Py_IS_TYPE(next, &PyTraceBack_Type)) {
+ break;
+ }
+ else {
+ traceback = next;
+ }
}
PyFrameObject *frame = traceback->tb_frame;