summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Modules/posixmodule.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2026-02-07 19:56:35 +0300
committershadchin <[email protected]>2026-02-07 20:23:53 +0300
commit19d43a3e6fb4cb8ea11747d7d7bca7a3542fbb44 (patch)
tree0b1418938140a0b6470953bef6069454ffdf1bd0 /contrib/tools/python3/Modules/posixmodule.c
parent0879409bfc0891ab8103828a3bdbf0e960475fec (diff)
Update Python 3 to 3.13.12
commit_hash:71d3efea437a769b2b7910d196120bb02587046e
Diffstat (limited to 'contrib/tools/python3/Modules/posixmodule.c')
-rw-r--r--contrib/tools/python3/Modules/posixmodule.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/contrib/tools/python3/Modules/posixmodule.c b/contrib/tools/python3/Modules/posixmodule.c
index 698e707b62d..24df9546064 100644
--- a/contrib/tools/python3/Modules/posixmodule.c
+++ b/contrib/tools/python3/Modules/posixmodule.c
@@ -1534,7 +1534,7 @@ static int
fd_and_follow_symlinks_invalid(const char *function_name, int fd,
int follow_symlinks)
{
- if ((fd > 0) && (!follow_symlinks)) {
+ if ((fd >= 0) && (!follow_symlinks)) {
PyErr_Format(PyExc_ValueError,
"%s: cannot use fd and follow_symlinks together",
function_name);
@@ -1699,7 +1699,7 @@ convertenviron(void)
#ifdef MS_WINDOWS
k = PyUnicode_FromWideChar(*e, (Py_ssize_t)(p-*e));
#else
- k = PyBytes_FromStringAndSize(*e, (int)(p-*e));
+ k = PyBytes_FromStringAndSize(*e, (Py_ssize_t)(p-*e));
#endif
if (k == NULL) {
Py_DECREF(d);
@@ -6741,8 +6741,8 @@ static EXECV_CHAR**
parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
{
Py_ssize_t i, pos, envc;
- PyObject *keys=NULL, *vals=NULL;
- PyObject *key2, *val2, *keyval;
+ PyObject *keys = NULL, *vals = NULL;
+ PyObject *key = NULL, *val = NULL, *key2 = NULL, *val2 = NULL;
EXECV_CHAR **envlist;
i = PyMapping_Size(env);
@@ -6767,20 +6767,22 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
}
for (pos = 0; pos < i; pos++) {
- PyObject *key = PyList_GetItem(keys, pos); // Borrowed ref.
+ // The 'key' and 'val' must be strong references because of
+ // possible side-effects by PyUnicode_FS{Converter,Decoder}().
+ key = PyList_GetItemRef(keys, pos);
if (key == NULL) {
goto error;
}
- PyObject *val = PyList_GetItem(vals, pos); // Borrowed ref.
+ val = PyList_GetItemRef(vals, pos);
if (val == NULL) {
goto error;
}
#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
- if (!PyUnicode_FSDecoder(key, &key2))
+ if (!PyUnicode_FSDecoder(key, &key2)) {
goto error;
+ }
if (!PyUnicode_FSDecoder(val, &val2)) {
- Py_DECREF(key2);
goto error;
}
/* Search from index 1 because on Windows starting '=' is allowed for
@@ -6789,39 +6791,38 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
PyUnicode_FindChar(key2, '=', 1, PyUnicode_GET_LENGTH(key2), 1) != -1)
{
PyErr_SetString(PyExc_ValueError, "illegal environment variable name");
- Py_DECREF(key2);
- Py_DECREF(val2);
goto error;
}
- keyval = PyUnicode_FromFormat("%U=%U", key2, val2);
+ PyObject *keyval = PyUnicode_FromFormat("%U=%U", key2, val2);
#else
- if (!PyUnicode_FSConverter(key, &key2))
+ if (!PyUnicode_FSConverter(key, &key2)) {
goto error;
+ }
if (!PyUnicode_FSConverter(val, &val2)) {
- Py_DECREF(key2);
goto error;
}
if (PyBytes_GET_SIZE(key2) == 0 ||
strchr(PyBytes_AS_STRING(key2) + 1, '=') != NULL)
{
PyErr_SetString(PyExc_ValueError, "illegal environment variable name");
- Py_DECREF(key2);
- Py_DECREF(val2);
goto error;
}
- keyval = PyBytes_FromFormat("%s=%s", PyBytes_AS_STRING(key2),
- PyBytes_AS_STRING(val2));
+ PyObject *keyval = PyBytes_FromFormat("%s=%s", PyBytes_AS_STRING(key2),
+ PyBytes_AS_STRING(val2));
#endif
- Py_DECREF(key2);
- Py_DECREF(val2);
- if (!keyval)
+ if (!keyval) {
goto error;
+ }
if (!fsconvert_strdup(keyval, &envlist[envc++])) {
Py_DECREF(keyval);
goto error;
}
+ Py_CLEAR(key);
+ Py_CLEAR(val);
+ Py_CLEAR(key2);
+ Py_CLEAR(val2);
Py_DECREF(keyval);
}
Py_DECREF(vals);
@@ -6832,6 +6833,10 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
return envlist;
error:
+ Py_XDECREF(key);
+ Py_XDECREF(val);
+ Py_XDECREF(key2);
+ Py_XDECREF(val2);
Py_XDECREF(keys);
Py_XDECREF(vals);
free_string_array(envlist, envc);
@@ -7353,7 +7358,7 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
if (argc < 1) {
PyErr_Format(PyExc_ValueError,
"%s: argv must not be empty", func_name);
- return NULL;
+ goto exit;
}
if (!PyMapping_Check(env) && env != Py_None) {