]> granicus.if.org Git - python/commitdiff
Issue #28732: Raise ValueError when os.spawn*() is passed an empty tuple of arguments
authorSteve Dower <steve.dower@microsoft.com>
Sun, 20 Nov 2016 02:53:19 +0000 (18:53 -0800)
committerSteve Dower <steve.dower@microsoft.com>
Sun, 20 Nov 2016 02:53:19 +0000 (18:53 -0800)
Lib/test/test_os.py
Modules/posixmodule.c

index b3d0b1e1c38c271eae980e76f52b8d5392842a9c..9194a8a2beb39168cf4fe2eb813176e5c9f2cee4 100644 (file)
@@ -2321,6 +2321,27 @@ class SpawnTests(unittest.TestCase):
         exitcode = os.spawnve(os.P_WAIT, args[0], args, self.env)
         self.assertEqual(exitcode, self.exitcode)
 
+    @requires_os_func('spawnl')
+    def test_spawnl_noargs(self):
+        args = self.create_args()
+        self.assertRaises(ValueError, os.spawnl, os.P_NOWAIT, args[0])
+
+    @requires_os_func('spawnle')
+    def test_spawnl_noargs(self):
+        args = self.create_args()
+        self.assertRaises(ValueError, os.spawnle, os.P_NOWAIT, args[0], {})
+
+    @requires_os_func('spawnv')
+    def test_spawnv_noargs(self):
+        args = self.create_args()
+        self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], ())
+        self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], [])
+
+    @requires_os_func('spawnve')
+    def test_spawnv_noargs(self):
+        args = self.create_args()
+        self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], (), {})
+        self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], [], {})
 
 # The introduction of this TestCase caused at least two different errors on
 # *nix buildbots. Temporarily skip this to let the buildbots move along.
index a89da7091bb27646732a1e4a3882a0c9cc9dea6c..0482f2bbd034cf1ebcbcc94325b38d1b1835f424 100644 (file)
@@ -5042,6 +5042,11 @@ os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv)
                         "spawnv() arg 2 must be a tuple or list");
         return NULL;
     }
+    if (argc == 0) {
+        PyErr_SetString(PyExc_ValueError,
+            "spawnv() arg 2 cannot be empty");
+        return NULL;
+    }
 
     argvlist = PyMem_NEW(EXECV_CHAR *, argc+1);
     if (argvlist == NULL) {
@@ -5127,6 +5132,11 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
                         "spawnve() arg 2 must be a tuple or list");
         goto fail_0;
     }
+    if (argc == 0) {
+        PyErr_SetString(PyExc_ValueError,
+            "spawnve() arg 2 cannot be empty");
+        goto fail_0;
+    }
     if (!PyMapping_Check(env)) {
         PyErr_SetString(PyExc_TypeError,
                         "spawnve() arg 3 must be a mapping object");