From 6790d606ffb44b24129552fca5418c0d408aac05 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Thu, 30 Aug 2007 17:15:14 +0000 Subject: Forbid an empty argument list in execv call. Fixes issue 1039. --- Lib/test/test_os.py | 3 +++ Modules/posixmodule.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index a5f5de3..085e6fa 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -441,6 +441,9 @@ class ExecTests(unittest.TestCase): def test_execvpe_with_bad_program(self): self.assertRaises(OSError, os.execvpe, 'no such app-', [], None) + def test_execvpe_with_bad_arglist(self): + self.assertRaises(ValueError, os.execvpe, 'notepad', [], None) + class Win32ErrorTests(unittest.TestCase): def test_rename(self): self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak") diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 4e6e0c5..5f8cde6 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2834,6 +2834,11 @@ posix_execv(PyObject *self, PyObject *args) PyMem_Free(path); return NULL; } + if (argc < 1) { + PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty"); + PyMem_Free(path); + return NULL; + } argvlist = PyMem_NEW(char *, argc+1); if (argvlist == NULL) { -- cgit v0.12