Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed a crash in :class:`subprocess.Popen` (and ``_posixsubprocess.fork_exec``)
when an ``argv`` item's :meth:`~os.PathLike.__fspath__` concurrently mutates the
``args`` sequence being converted.
8 changes: 7 additions & 1 deletion Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,14 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
goto cleanup;
}
borrowed_arg = PySequence_Fast_GET_ITEM(fast_args, arg_num);
if (PyUnicode_FSConverter(borrowed_arg, &converted_arg) == 0)
/* borrowed_arg is only borrowed; its __fspath__() may run Python
that drops fast_args' last reference to it. */
Py_INCREF(borrowed_arg);
if (PyUnicode_FSConverter(borrowed_arg, &converted_arg) == 0) {
Py_DECREF(borrowed_arg);
goto cleanup;
}
Py_DECREF(borrowed_arg);
PyTuple_SET_ITEM(converted_args, arg_num, converted_arg);
}

Expand Down
Loading