[Python-checkins] bpo-38410: Properly handle PySys_Audit() failures (GH-16657)

Zackery Spytz webhook-mailer at python.org
Thu Mar 26 08:11:40 EDT 2020


https://github.com/python/cpython/commit/79ceccd1ec6ef7e487da2916f32c6f0d1477bd3d
commit: 79ceccd1ec6ef7e487da2916f32c6f0d1477bd3d
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-03-26T12:11:13Z
summary:

bpo-38410: Properly handle PySys_Audit() failures (GH-16657)

files:
A Misc/NEWS.d/next/Library/2019-10-09-08-14-25.bpo-38410._YyoMV.rst
M Include/cpython/ceval.h
M Python/ceval.c
M Python/sysmodule.c

diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h
index 74599370c10c8..020f78712ff50 100644
--- a/Include/cpython/ceval.h
+++ b/Include/cpython/ceval.h
@@ -11,9 +11,9 @@ PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyO
 PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
 PyAPI_FUNC(int) _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
 PyAPI_FUNC(int) _PyEval_GetCoroutineOriginTrackingDepth(void);
-PyAPI_FUNC(void) _PyEval_SetAsyncGenFirstiter(PyObject *);
+PyAPI_FUNC(int) _PyEval_SetAsyncGenFirstiter(PyObject *);
 PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFirstiter(void);
-PyAPI_FUNC(void) _PyEval_SetAsyncGenFinalizer(PyObject *);
+PyAPI_FUNC(int) _PyEval_SetAsyncGenFinalizer(PyObject *);
 PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void);
 
 /* Helper to look up a builtin object */
diff --git a/Misc/NEWS.d/next/Library/2019-10-09-08-14-25.bpo-38410._YyoMV.rst b/Misc/NEWS.d/next/Library/2019-10-09-08-14-25.bpo-38410._YyoMV.rst
new file mode 100644
index 0000000000000..038c46afb5bb6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-10-09-08-14-25.bpo-38410._YyoMV.rst
@@ -0,0 +1,2 @@
+Properly handle :func:`sys.audit` failures in
+:func:`sys.set_asyncgen_hooks`.
diff --git a/Python/ceval.c b/Python/ceval.c
index 836457d1a57a4..afaa6ff1b3c51 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4785,17 +4785,18 @@ _PyEval_GetCoroutineOriginTrackingDepth(void)
     return tstate->coroutine_origin_tracking_depth;
 }
 
-void
+int
 _PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
 {
     PyThreadState *tstate = _PyThreadState_GET();
 
     if (PySys_Audit("sys.set_asyncgen_hook_firstiter", NULL) < 0) {
-        return;
+        return -1;
     }
 
     Py_XINCREF(firstiter);
     Py_XSETREF(tstate->async_gen_firstiter, firstiter);
+    return 0;
 }
 
 PyObject *
@@ -4805,17 +4806,18 @@ _PyEval_GetAsyncGenFirstiter(void)
     return tstate->async_gen_firstiter;
 }
 
-void
+int
 _PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
 {
     PyThreadState *tstate = _PyThreadState_GET();
 
     if (PySys_Audit("sys.set_asyncgen_hook_finalizer", NULL) < 0) {
-        return;
+        return -1;
     }
 
     Py_XINCREF(finalizer);
     Py_XSETREF(tstate->async_gen_finalizer, finalizer);
+    return 0;
 }
 
 PyObject *
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index c78a627380522..c877fd76ace8b 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1222,10 +1222,12 @@ sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
                           Py_TYPE(finalizer)->tp_name);
             return NULL;
         }
-        _PyEval_SetAsyncGenFinalizer(finalizer);
+        if (_PyEval_SetAsyncGenFinalizer(finalizer) < 0) {
+            return NULL;
+        }
     }
-    else if (finalizer == Py_None) {
-        _PyEval_SetAsyncGenFinalizer(NULL);
+    else if (finalizer == Py_None && _PyEval_SetAsyncGenFinalizer(NULL) < 0) {
+        return NULL;
     }
 
     if (firstiter && firstiter != Py_None) {
@@ -1235,10 +1237,12 @@ sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
                           Py_TYPE(firstiter)->tp_name);
             return NULL;
         }
-        _PyEval_SetAsyncGenFirstiter(firstiter);
+        if (_PyEval_SetAsyncGenFirstiter(firstiter) < 0) {
+            return NULL;
+        }
     }
-    else if (firstiter == Py_None) {
-        _PyEval_SetAsyncGenFirstiter(NULL);
+    else if (firstiter == Py_None && _PyEval_SetAsyncGenFirstiter(NULL) < 0) {
+        return NULL;
     }
 
     Py_RETURN_NONE;



More information about the Python-checkins mailing list