Kaydet (Commit) 50422b40 authored tarafından Guido van Rossum's avatar Guido van Rossum

Michael Hudson:

This patch changes posixmodule.c:execv to

a) check for zero length args (does this to execve, too), raising
   ValueError.

b) raises more rational exceptions for various flavours of duff arguments.
   I *hate*
      TypeError: "illegal argument type for built-in operation"
   It has to be one of the most frustrating error messages ever.
üst 868b50af
...@@ -1343,8 +1343,12 @@ posix_execv(self, args) ...@@ -1343,8 +1343,12 @@ posix_execv(self, args)
getitem = PyTuple_GetItem; getitem = PyTuple_GetItem;
} }
else { else {
badarg: PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
PyErr_BadArgument(); return NULL;
}
if (argc == 0) {
PyErr_SetString(PyExc_ValueError, "empty argument list");
return NULL; return NULL;
} }
...@@ -1354,7 +1358,10 @@ posix_execv(self, args) ...@@ -1354,7 +1358,10 @@ posix_execv(self, args)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) { if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
PyMem_DEL(argvlist); PyMem_DEL(argvlist);
goto badarg; PyErr_SetString(PyExc_TypeError,
"all arguments must be strings");
return NULL;
} }
} }
argvlist[argc] = NULL; argvlist[argc] = NULL;
...@@ -1416,6 +1423,12 @@ posix_execve(self, args) ...@@ -1416,6 +1423,12 @@ posix_execve(self, args)
return NULL; return NULL;
} }
if (argc == 0) {
PyErr_SetString(PyExc_ValueError,
"empty argument list");
return NULL;
}
argvlist = PyMem_NEW(char *, argc+1); argvlist = PyMem_NEW(char *, argc+1);
if (argvlist == NULL) { if (argvlist == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment