[issue8036] raise ValueError for empty `path` in os.spawnv[e]
Eryk Sun
report at bugs.python.org
Mon Mar 1 10:27:31 EST 2021
Eryk Sun <eryksun at gmail.com> added the comment:
The internal spawn function in ucrt, common_spawnv(), verifies its parameters as follows:
_VALIDATE_RETURN(file_name != nullptr, EINVAL, -1);
_VALIDATE_RETURN(file_name[0] != '\0', EINVAL, -1);
_VALIDATE_RETURN(arguments != nullptr, EINVAL, -1);
_VALIDATE_RETURN(arguments[0] != nullptr, EINVAL, -1);
_VALIDATE_RETURN(arguments[0][0] != '\0', EINVAL, -1);
Currently os.spawnv() and os.spawnve() check for and raise ValueError for all of these cases except the second one, in which file_name is an empty string. Microsoft doesn't document this case [1]:
These functions validate their parameters. If either cmdname or argv
is a null pointer, or if argv points to null pointer, or argv[0] is
an empty string, the invalid parameter handler is invoked, as
described in Parameter Validation.
In a release build, this case fails with EINVAL. In a debug build, the default error-reporting settings display a pop message about the invalid argument. The message box is easy enough to suppress. But for the sake of consistency with the other cases, os_spawnv_impl in Modules/posixmodule.c should raise a ValueError if `path` is an empty string. For example:
#ifdef HAVE_WSPAWNV
if (!path->wide[0]) {
PyErr_SetString(PyExc_ValueError,
"spawnv() arg 1 cannot be an empty string");
return NULL;
}
#endif
---
[1] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/spawnv-wspawnv
----------
components: +Windows
nosy: +paul.moore, steve.dower, tim.golden, zach.ware
priority: high -> normal
title: Interpreter crashes on invalid arg to spawnl on Windows -> raise ValueError for empty `path` in os.spawnv[e]
type: crash -> behavior
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 2.7, Python 3.2, Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue8036>
_______________________________________
More information about the Python-bugs-list
mailing list