]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-126654: Fix crash in several functions in `_interpreters` module (GH-126678...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 11 Nov 2024 12:01:22 +0000 (13:01 +0100)
committerGitHub <noreply@github.com>
Mon, 11 Nov 2024 12:01:22 +0000 (12:01 +0000)
gh-126654: Fix crash in several functions in `_interpreters` module (GH-126678)
(cherry picked from commit 9fc2808eaf4e74a9f52f44d20a7d1110bd949d41)

Co-authored-by: sobolevn <mail@sobolevn.me>
Lib/test/test__interpreters.py
Misc/NEWS.d/next/Library/2024-11-11-13-00-21.gh-issue-126654.4gfP2y.rst [new file with mode: 0644]
Modules/_interpretersmodule.c

index beeb280894ea99c73ea07e35b3d671ad4f310eff..533120a3221987117eb81682980f1bfa00f8ca2b 100644 (file)
@@ -551,6 +551,24 @@ class DestroyTests(TestBase):
             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 (file)
index 0000000..750158e
--- /dev/null
@@ -0,0 +1,2 @@
+Fix crash when non-dict was passed to several functions in ``_interpreters``
+module.
index 7933febf3cacfc7e957a71a723edb4be2744366f..706316234c7d24f71b3e7e868d683bd1f39bc120 100644 (file)
@@ -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;