Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2658260

Browse files
committed
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Author: Daniel Diniz Reviewer: Georg Brandl
1 parent 3c9d2ef commit 2658260

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Python/pythonrun.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,13 @@ print_exception(PyObject *f, PyObject *value)
13001300
int err = 0;
13011301
PyObject *type, *tb;
13021302

1303+
if (!PyExceptionInstance_Check(value)) {
1304+
PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f);
1305+
PyFile_WriteString(Py_TYPE(value)->tp_name, f);
1306+
PyFile_WriteString(" found\n", f);
1307+
return;
1308+
}
1309+
13031310
Py_INCREF(value);
13041311
fflush(stdout);
13051312
type = (PyObject *) Py_TYPE(value);

0 commit comments

Comments
 (0)