Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test__interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix crash when non-dict was passed to several functions in ``_interpreters``
module.
5 changes: 5 additions & 0 deletions Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading