mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
[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 46bfd26fb2
)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
parent
5017c81824
commit
2813a61675
2 changed files with 9 additions and 0 deletions
|
@ -1650,6 +1650,10 @@ class LowLevelTests(TestBase):
|
||||||
self.assertIs(after2, None)
|
self.assertIs(after2, None)
|
||||||
self.assertEqual(after3.type.__name__, 'AssertionError')
|
self.assertEqual(after3.type.__name__, 'AssertionError')
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
# GH-127165: Embedded NULL characters broke the lookup
|
||||||
|
_interpreters.set___main___attrs(interpid, {"\x00": 1})
|
||||||
|
|
||||||
with self.subTest('from C-API'):
|
with self.subTest('from C-API'):
|
||||||
with self.interpreter_from_capi() as interpid:
|
with self.interpreter_from_capi() as interpid:
|
||||||
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
|
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
|
||||||
|
|
|
@ -346,6 +346,11 @@ _copy_string_obj_raw(PyObject *strobj, Py_ssize_t *p_size)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (size != (Py_ssize_t)strlen(str)) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "found embedded NULL character");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char *copied = PyMem_RawMalloc(size+1);
|
char *copied = PyMem_RawMalloc(size+1);
|
||||||
if (copied == NULL) {
|
if (copied == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue