From c732eccbae1fdec433a99d317cc89bda4fc08ff1 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 16 Nov 2022 20:06:46 +0000 Subject: [PATCH 1/3] gh-99377: Prevent raising audit event when thread state has not actually been set. This can occur during initialization. Without the check, later calls to get the interpreter state will cause a fatal error. --- Python/pystate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/pystate.c b/Python/pystate.c index a53a9a3494a02a..280d3fe2082fd5 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -875,7 +875,9 @@ PyThreadState_New(PyInterpreterState *interp) PyThreadState *tstate = new_threadstate(interp); if (tstate) { _PyThreadState_SetCurrent(tstate); - if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) { + if (_PyThreadState_GET() + && PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0 + ) { PyThreadState_Clear(tstate); _PyThreadState_DeleteCurrent(tstate); return NULL; From f1e223ccd2895329a7df453e45dc363091fabf9b Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 16 Nov 2022 21:39:33 +0000 Subject: [PATCH 2/3] Revert --- Lib/test/test_audit.py | 8 -------- Python/pystate.c | 21 +-------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/Lib/test/test_audit.py b/Lib/test/test_audit.py index 5a2997ac9e6f18..70f8a77a4761a7 100644 --- a/Lib/test/test_audit.py +++ b/Lib/test/test_audit.py @@ -197,19 +197,11 @@ def test_threading(self): actual = [(ev[0], ev[2]) for ev in events] expected = [ ("_thread.start_new_thread", "(, (), None)"), - ("cpython.PyThreadState_New", "(2,)"), ("test.test_func", "()"), - ("cpython.PyThreadState_Clear", "(2,)"), ] self.assertEqual(actual, expected) - def test_threading_abort(self): - # Ensures that aborting PyThreadState_New raises the correct exception - returncode, events, stderr = self.run_python("test_threading_abort") - if returncode: - self.fail(stderr) - def test_wmi_exec_query(self): import_helper.import_module("_wmi") diff --git a/Python/pystate.c b/Python/pystate.c index 280d3fe2082fd5..c7f2386f8c6329 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -875,13 +875,6 @@ PyThreadState_New(PyInterpreterState *interp) PyThreadState *tstate = new_threadstate(interp); if (tstate) { _PyThreadState_SetCurrent(tstate); - if (_PyThreadState_GET() - && PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0 - ) { - PyThreadState_Clear(tstate); - _PyThreadState_DeleteCurrent(tstate); - return NULL; - } } return tstate; } @@ -889,15 +882,7 @@ PyThreadState_New(PyInterpreterState *interp) PyThreadState * _PyThreadState_Prealloc(PyInterpreterState *interp) { - PyThreadState *tstate = new_threadstate(interp); - if (tstate) { - if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) { - PyThreadState_Clear(tstate); - _PyThreadState_Delete(tstate, 0); - return NULL; - } - } - return tstate; + return new_threadstate(interp); } // We keep this around for (accidental) stable ABI compatibility. @@ -1045,10 +1030,6 @@ _PyInterpreterState_ClearModules(PyInterpreterState *interp) void PyThreadState_Clear(PyThreadState *tstate) { - if (PySys_Audit("cpython.PyThreadState_Clear", "K", tstate->id) < 0) { - PyErr_WriteUnraisable(NULL); - } - int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose; if (verbose && tstate->cframe->current_frame != NULL) { From 682843b0e517b4c2270b1e2f31c66dddf53783d1 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 16 Nov 2022 23:38:05 +0000 Subject: [PATCH 3/3] Remove docs --- Doc/c-api/init.rst | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 273838c1db28ea..afb17719a77ab2 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -1239,25 +1239,12 @@ All of the following functions must be called after :c:func:`Py_Initialize`. The global interpreter lock need not be held, but may be held if it is necessary to serialize calls to this function. - .. audit-event:: cpython.PyThreadState_New id c.PyThreadState_New - - Raise an auditing event ``cpython.PyThreadState_New`` with Python's thread - id as the argument. The event will be raised from the thread creating the new - ``PyThreadState``, which may not be the new thread. - .. c:function:: void PyThreadState_Clear(PyThreadState *tstate) Reset all information in a thread state object. The global interpreter lock must be held. - .. audit-event:: cpython.PyThreadState_Clear id c.PyThreadState_Clear - - Raise an auditing event ``cpython.PyThreadState_Clear`` with Python's - thread id as the argument. The event may be raised from a different thread - than the one being cleared. Exceptions raised from a hook will be treated - as unraisable and will not abort the operation. - .. versionchanged:: 3.9 This function now calls the :c:member:`PyThreadState.on_delete` callback. Previously, that happened in :c:func:`PyThreadState_Delete`. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy