0
0
mirror of https://github.com/python/cpython.git synced 2024-11-24 17:47:13 +01:00

gh-126654: Fix crash in several functions in _interpreters module (#126678)

This commit is contained in:
sobolevn 2024-11-11 14:35:56 +03:00 committed by GitHub
parent 6ee542d491
commit 9fc2808eaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 0 deletions

View 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):

View File

@ -0,0 +1,2 @@
Fix crash when non-dict was passed to several functions in ``_interpreters``
module.

View File

@ -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;