Skip to content

Commit 2813a61

Browse files
[3.13] gh-127165: Disallow embedded NULL characters in _interpreters (GH-127199) (#127463)
gh-127165: Disallow embedded NULL characters in `_interpreters` (GH-127199) (cherry picked from commit 46bfd26) Co-authored-by: Peter Bierma <[email protected]>
1 parent 5017c81 commit 2813a61

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Lib/test/test_interpreters/test_api.py

+4
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,10 @@ def test_set___main___attrs(self):
16501650
self.assertIs(after2, None)
16511651
self.assertEqual(after3.type.__name__, 'AssertionError')
16521652

1653+
with self.assertRaises(ValueError):
1654+
# GH-127165: Embedded NULL characters broke the lookup
1655+
_interpreters.set___main___attrs(interpid, {"\x00": 1})
1656+
16531657
with self.subTest('from C-API'):
16541658
with self.interpreter_from_capi() as interpid:
16551659
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):

Python/crossinterp.c

+5
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ _copy_string_obj_raw(PyObject *strobj, Py_ssize_t *p_size)
346346
return NULL;
347347
}
348348

349+
if (size != (Py_ssize_t)strlen(str)) {
350+
PyErr_SetString(PyExc_ValueError, "found embedded NULL character");
351+
return NULL;
352+
}
353+
349354
char *copied = PyMem_RawMalloc(size+1);
350355
if (copied == NULL) {
351356
PyErr_NoMemory();

0 commit comments

Comments
 (0)