Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 859fd7b

Browse files
committed
Issue #28732: Raise ValueError when os.spawn*() is passed an empty tuple of arguments
1 parent c363061 commit 859fd7b

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lib/test/test_os.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,27 @@ def test_spawnve_bytes(self):
23212321
exitcode = os.spawnve(os.P_WAIT, args[0], args, self.env)
23222322
self.assertEqual(exitcode, self.exitcode)
23232323

2324+
@requires_os_func('spawnl')
2325+
def test_spawnl_noargs(self):
2326+
args = self.create_args()
2327+
self.assertRaises(ValueError, os.spawnl, os.P_NOWAIT, args[0])
2328+
2329+
@requires_os_func('spawnle')
2330+
def test_spawnl_noargs(self):
2331+
args = self.create_args()
2332+
self.assertRaises(ValueError, os.spawnle, os.P_NOWAIT, args[0], {})
2333+
2334+
@requires_os_func('spawnv')
2335+
def test_spawnv_noargs(self):
2336+
args = self.create_args()
2337+
self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], ())
2338+
self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], [])
2339+
2340+
@requires_os_func('spawnve')
2341+
def test_spawnv_noargs(self):
2342+
args = self.create_args()
2343+
self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], (), {})
2344+
self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], [], {})
23242345

23252346
# The introduction of this TestCase caused at least two different errors on
23262347
# *nix buildbots. Temporarily skip this to let the buildbots move along.

Modules/posixmodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,6 +5042,11 @@ os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv)
50425042
"spawnv() arg 2 must be a tuple or list");
50435043
return NULL;
50445044
}
5045+
if (argc == 0) {
5046+
PyErr_SetString(PyExc_ValueError,
5047+
"spawnv() arg 2 cannot be empty");
5048+
return NULL;
5049+
}
50455050

50465051
argvlist = PyMem_NEW(EXECV_CHAR *, argc+1);
50475052
if (argvlist == NULL) {
@@ -5127,6 +5132,11 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
51275132
"spawnve() arg 2 must be a tuple or list");
51285133
goto fail_0;
51295134
}
5135+
if (argc == 0) {
5136+
PyErr_SetString(PyExc_ValueError,
5137+
"spawnve() arg 2 cannot be empty");
5138+
goto fail_0;
5139+
}
51305140
if (!PyMapping_Check(env)) {
51315141
PyErr_SetString(PyExc_TypeError,
51325142
"spawnve() arg 3 must be a mapping object");

0 commit comments

Comments
 (0)