summaryrefslogtreecommitdiffstats
path: root/Modules/_posixsubprocess.c
diff options
context:
space:
mode:
authorchgnrdv <52372310+chgnrdv@users.noreply.github.com>2023-06-04 04:06:45 (GMT)
committerGitHub <noreply@github.com>2023-06-04 04:06:45 (GMT)
commitce558e69d4087dd3653207de78345fbb8a2c7835 (patch)
treea96a5b705ac12fced6d95ca55787d270550edbf8 /Modules/_posixsubprocess.c
parenteaff9c39aa1a70d401521847cc35bec883ae9772 (diff)
downloadcpython-ce558e69d4087dd3653207de78345fbb8a2c7835.zip
cpython-ce558e69d4087dd3653207de78345fbb8a2c7835.tar.gz
cpython-ce558e69d4087dd3653207de78345fbb8a2c7835.tar.bz2
gh-104690 Disallow thread creation and fork at interpreter finalization (#104826)
Disallow thread creation and fork at interpreter finalization. in the following functions, check if interpreter is finalizing and raise `RuntimeError` with appropriate message: * `_thread.start_new_thread` and thus `threading` * `posix.fork` * `posix.fork1` * `posix.forkpty` * `_posixsubprocess.fork_exec` when a `preexec_fn=` is supplied. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r--Modules/_posixsubprocess.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index 3647080..2d88f5e 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -5,6 +5,7 @@
#include "Python.h"
#include "pycore_fileutils.h"
+#include "pycore_pystate.h"
#if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
#endif
@@ -943,6 +944,11 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
Py_ssize_t fds_to_keep_len = PyTuple_GET_SIZE(py_fds_to_keep);
PyInterpreterState *interp = PyInterpreterState_Get();
+ if ((preexec_fn != Py_None) && interp->finalizing) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "preexec_fn not supported at interpreter shutdown");
+ return NULL;
+ }
if ((preexec_fn != Py_None) && (interp != PyInterpreterState_Main())) {
PyErr_SetString(PyExc_RuntimeError,
"preexec_fn not supported within subinterpreters");