diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-12 16:50:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-12 16:50:58 (GMT) |
commit | 77bdeebdda3358186df6e6ba900c562ddaefaa5c (patch) | |
tree | 15dfc0b54a68a195c42c6e83cb0bf03b9af7e020 /Modules | |
parent | 2eed1f5868b1c54a5314b64c38010258d27658da (diff) | |
download | cpython-77bdeebdda3358186df6e6ba900c562ddaefaa5c.zip cpython-77bdeebdda3358186df6e6ba900c562ddaefaa5c.tar.gz cpython-77bdeebdda3358186df6e6ba900c562ddaefaa5c.tar.bz2 |
[3.12] gh-105436: The environment block should end with two null wchar_t values (GH-105495) (#105700)
gh-105436: The environment block should end with two null wchar_t values (GH-105495)
(cherry picked from commit 4f7d3b602d47d61137e82145f601dccfe6f6cd3c)
Co-authored-by: Dora203 <66343334+sku2000@users.noreply.github.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_winapi.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Modules/_winapi.c b/Modules/_winapi.c index bbc9fac..d6d2f4a 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -796,6 +796,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"); @@ -869,7 +880,8 @@ getenvironment(PyObject* environment) *p++ = L'\0'; assert(p == end); - error: +cleanup: +error: Py_XDECREF(keys); Py_XDECREF(values); return buffer; |