Skip to content

Commit 1aa1f2f

Browse files
ZeroIntensitysrinivasreddy
authored andcommitted
pythongh-127165: Disallow embedded NULL characters in _interpreters (python#127199)
1 parent a2e6c87 commit 1aa1f2f

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
@@ -1649,6 +1649,10 @@ def test_set___main___attrs(self):
16491649
self.assertIs(after2, None)
16501650
self.assertEqual(after3.type.__name__, 'AssertionError')
16511651

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

Python/crossinterp.c

+5
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ _copy_string_obj_raw(PyObject *strobj, Py_ssize_t *p_size)
342342
return NULL;
343343
}
344344

345+
if (size != (Py_ssize_t)strlen(str)) {
346+
PyErr_SetString(PyExc_ValueError, "found embedded NULL character");
347+
return NULL;
348+
}
349+
345350
char *copied = PyMem_RawMalloc(size+1);
346351
if (copied == NULL) {
347352
PyErr_NoMemory();

0 commit comments

Comments
 (0)