diff options
author | sobolevn <mail@sobolevn.me> | 2024-11-11 11:35:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-11 11:35:56 (GMT) |
commit | 9fc2808eaf4e74a9f52f44d20a7d1110bd949d41 (patch) | |
tree | cb6853a90f56029aadaeb6fb0d097ef7b898e5c3 | |
parent | 6ee542d491589b470ec7cdd353463ff9ff52d098 (diff) | |
download | cpython-9fc2808eaf4e74a9f52f44d20a7d1110bd949d41.zip cpython-9fc2808eaf4e74a9f52f44d20a7d1110bd949d41.tar.gz cpython-9fc2808eaf4e74a9f52f44d20a7d1110bd949d41.tar.bz2 |
gh-126654: Fix crash in several functions in `_interpreters` module (#126678)
-rw-r--r-- | Lib/test/test__interpreters.py | 18 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2024-11-11-13-00-21.gh-issue-126654.4gfP2y.rst | 2 | ||||
-rw-r--r-- | Modules/_interpretersmodule.c | 5 |
3 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test__interpreters.py b/Lib/test/test__interpreters.py index 14cd50b..bf3165e 100644 --- a/Lib/test/test__interpreters.py +++ b/Lib/test/test__interpreters.py @@ -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 index 0000000..750158e --- /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 95acdd6..a9a966e 100644 --- a/Modules/_interpretersmodule.c +++ b/Modules/_interpretersmodule.c @@ -936,6 +936,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; |