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

Skip to content

Commit 50422b4

Browse files
committed
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.
1 parent 868b50a commit 50422b4

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

Modules/posixmodule.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,12 @@ posix_execv(self, args)
13431343
getitem = PyTuple_GetItem;
13441344
}
13451345
else {
1346-
badarg:
1347-
PyErr_BadArgument();
1346+
PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
1347+
return NULL;
1348+
}
1349+
1350+
if (argc == 0) {
1351+
PyErr_SetString(PyExc_ValueError, "empty argument list");
13481352
return NULL;
13491353
}
13501354

@@ -1354,7 +1358,10 @@ posix_execv(self, args)
13541358
for (i = 0; i < argc; i++) {
13551359
if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
13561360
PyMem_DEL(argvlist);
1357-
goto badarg;
1361+
PyErr_SetString(PyExc_TypeError,
1362+
"all arguments must be strings");
1363+
return NULL;
1364+
13581365
}
13591366
}
13601367
argvlist[argc] = NULL;
@@ -1416,6 +1423,12 @@ posix_execve(self, args)
14161423
return NULL;
14171424
}
14181425

1426+
if (argc == 0) {
1427+
PyErr_SetString(PyExc_ValueError,
1428+
"empty argument list");
1429+
return NULL;
1430+
}
1431+
14191432
argvlist = PyMem_NEW(char *, argc+1);
14201433
if (argvlist == NULL) {
14211434
PyErr_NoMemory();

0 commit comments

Comments
 (0)