bpo-38920: Add audit hooks for when sys.excepthook and sys.unraisable hooks are invoked (GH-17392)

Also fixes some potential segfaults in unraisable hook handling.
This commit is contained in:
Steve Dower 2019-11-28 08:46:11 -08:00 committed by GitHub
parent 02519f75d1
commit bea33f5e1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 156 additions and 50 deletions

View file

@ -695,6 +695,14 @@ _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars)
}
}
hook = _PySys_GetObjectId(&PyId_excepthook);
if (PySys_Audit("sys.excepthook", "OOOO", hook ? hook : Py_None,
exception, v, tb) < 0) {
if (PyErr_ExceptionMatches(PyExc_RuntimeError)) {
PyErr_Clear();
goto done;
}
_PyErr_WriteUnraisableMsg("in audit hook", NULL);
}
if (hook) {
PyObject* stack[3];
PyObject *result;