mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-111841: Fix os.putenv() and os.unsetenv() with embedded NUL on Windows (GH-111842)
This commit is contained in:
parent
2e7f070080
commit
0b06d2482d
4 changed files with 19 additions and 9 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue