https://github.com/python/cpython/commit/e194b217536416341dd54852c6773773c373f57e
commit: e194b217536416341dd54852c6773773c373f57e
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2024-11-11T12:01:22Z
summary:

[3.13] gh-126654: Fix crash in several functions in `_interpreters` module 
(GH-126678) (#126681)

gh-126654: Fix crash in several functions in `_interpreters` module (GH-126678)
(cherry picked from commit 9fc2808eaf4e74a9f52f44d20a7d1110bd949d41)

Co-authored-by: sobolevn <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-11-11-13-00-21.gh-issue-126654.4gfP2y.rst
M Lib/test/test__interpreters.py
M Modules/_interpretersmodule.c

diff --git a/Lib/test/test__interpreters.py b/Lib/test/test__interpreters.py
index beeb280894ea99..533120a3221987 100644
--- a/Lib/test/test__interpreters.py
+++ b/Lib/test/test__interpreters.py
@@ -551,6 +551,24 @@ def test_still_running(self):
             self.assertTrue(_interpreters.is_running(interp))
 
 
+class CommonTests(TestBase):
+    def setUp(self):
+        super().setUp()
+        self.id = _interpreters.create()
+
+    def test_signatures(self):
+        # for method in ['exec', 'run_string', 'run_func']:
+        msg = "expected 'shared' to be a dict"
+        with self.assertRaisesRegex(TypeError, msg):
+            _interpreters.exec(self.id, 'a', 1)
+        with self.assertRaisesRegex(TypeError, msg):
+            _interpreters.exec(self.id, 'a', shared=1)
+        with self.assertRaisesRegex(TypeError, msg):
+            _interpreters.run_string(self.id, 'a', shared=1)
+        with self.assertRaisesRegex(TypeError, msg):
+            _interpreters.run_func(self.id, lambda: None, shared=1)
+
+
 class RunStringTests(TestBase):
 
     def setUp(self):
diff --git 
a/Misc/NEWS.d/next/Library/2024-11-11-13-00-21.gh-issue-126654.4gfP2y.rst 
b/Misc/NEWS.d/next/Library/2024-11-11-13-00-21.gh-issue-126654.4gfP2y.rst
new file mode 100644
index 00000000000000..750158e6d4d3ae
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-11-11-13-00-21.gh-issue-126654.4gfP2y.rst
@@ -0,0 +1,2 @@
+Fix crash when non-dict was passed to several functions in ``_interpreters``
+module.
diff --git a/Modules/_interpretersmodule.c b/Modules/_interpretersmodule.c
index 7933febf3cacfc..706316234c7d24 100644
--- a/Modules/_interpretersmodule.c
+++ b/Modules/_interpretersmodule.c
@@ -939,6 +939,11 @@ static int
 _interp_exec(PyObject *self, PyInterpreterState *interp,
              PyObject *code_arg, PyObject *shared_arg, PyObject **p_excinfo)
 {
+    if (shared_arg != NULL && !PyDict_CheckExact(shared_arg)) {
+        PyErr_SetString(PyExc_TypeError, "expected 'shared' to be a dict");
+        return -1;
+    }
+
     // Extract code.
     Py_ssize_t codestrlen = -1;
     PyObject *bytes_obj = NULL;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to