diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-11-10 16:42:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 16:42:14 (GMT) |
commit | 0b06d2482d77e02c5d40e221f6046c9c355458b2 (patch) | |
tree | 5401420104942e6729d7e9ea93bc89c9fd646ed9 /Modules | |
parent | 2e7f0700800c0337a0b1b9471fcef410e3158250 (diff) | |
download | cpython-0b06d2482d77e02c5d40e221f6046c9c355458b2.zip cpython-0b06d2482d77e02c5d40e221f6046c9c355458b2.tar.gz cpython-0b06d2482d77e02c5d40e221f6046c9c355458b2.tar.bz2 |
gh-111841: Fix os.putenv() and os.unsetenv() with embedded NUL on Windows (GH-111842)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 73b80e4..d99b533 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -12280,7 +12280,6 @@ win32_putenv(PyObject *name, PyObject *value) } Py_ssize_t size; - /* PyUnicode_AsWideCharString() rejects embedded null characters */ wchar_t *env = PyUnicode_AsWideCharString(unicode, &size); Py_DECREF(unicode); @@ -12294,6 +12293,12 @@ win32_putenv(PyObject *name, PyObject *value) PyMem_Free(env); return NULL; } + if (wcslen(env) != (size_t)size) { + PyErr_SetString(PyExc_ValueError, + "embedded null character"); + PyMem_Free(env); + return NULL; + } /* _wputenv() and SetEnvironmentVariableW() update the environment in the Process Environment Block (PEB). _wputenv() also updates CRT 'environ' |