mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.11] gh-105436: The environment block should end with two null wchar_t values (GH-105495) (#105701)
gh-105436: The environment block should end with two null wchar_t values (GH-105495)
(cherry picked from commit 4f7d3b602d
)
Co-authored-by: Dora203 <66343334+sku2000@users.noreply.github.com>
This commit is contained in:
parent
f5b63eab9b
commit
261d0b4f0e
3 changed files with 22 additions and 1 deletions
|
@ -805,6 +805,17 @@ getenvironment(PyObject* environment)
|
|||
}
|
||||
|
||||
envsize = PyList_GET_SIZE(keys);
|
||||
|
||||
if (envsize == 0) {
|
||||
// A environment block must be terminated by two null characters --
|
||||
// one for the last string and one for the block.
|
||||
buffer = PyMem_Calloc(2, sizeof(wchar_t));
|
||||
if (!buffer) {
|
||||
PyErr_NoMemory();
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (PyList_GET_SIZE(values) != envsize) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"environment changed size during iteration");
|
||||
|
@ -878,7 +889,8 @@ getenvironment(PyObject* environment)
|
|||
*p++ = L'\0';
|
||||
assert(p == end);
|
||||
|
||||
error:
|
||||
cleanup:
|
||||
error:
|
||||
Py_XDECREF(keys);
|
||||
Py_XDECREF(values);
|
||||
return buffer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue