Skip to content

bpo-30602: Fix lastarg in os.spawnve() #2287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2017
Merged
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
6 changes: 3 additions & 3 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5223,7 +5223,7 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Py_ssize_t argc, i, envc;
intptr_t spawnval;
PyObject *(*getitem)(PyObject *, Py_ssize_t);
Py_ssize_t lastarg = -1;
Py_ssize_t lastarg = 0;

/* spawnve has four arguments: (mode, path, argv, env), where
argv is a list or tuple of strings and env is a dictionary
Expand Down Expand Up @@ -5266,7 +5266,7 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
goto fail_1;
}
if (i == 0 && !argvlist[0][0]) {
lastarg = i;
lastarg = i + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can restore the initial value to Py_ssize_t lastarg = 0. But leaving it as -1 shouldn't be a problem since failures before this loop go to fail_0 instead of fail_1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

PyErr_SetString(
PyExc_ValueError,
"spawnv() arg 2 first element cannot be empty");
Expand Down Expand Up @@ -5302,7 +5302,7 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
fail_1:
free_string_array(argvlist, lastarg + 1);
free_string_array(argvlist, lastarg);
fail_0:
return res;
}
Expand Down