[Python-checkins] python/dist/src/Modules posixmodule.c,2.274,2.275
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Fri, 13 Dec 2002 10:36:37 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv21722
Modified Files:
posixmodule.c
Log Message:
execve(), spawnve(): add some extra sanity checking to env;
PyMapping_Check() doesn't guarantee that PyMapping_Size() won't raise
an exception, nor that keys and values are lists.
Also folded some long lines and did a little whitespace normalization.
Probably a 2.2 backport candidate.
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.274
retrieving revision 2.275
diff -C2 -d -r2.274 -r2.275
*** posixmodule.c 6 Dec 2002 12:48:50 -0000 2.274
--- posixmodule.c 13 Dec 2002 18:36:22 -0000 2.275
***************
*** 2315,2323 ****
}
else {
! PyErr_SetString(PyExc_TypeError, "execve() arg 2 must be a tuple or list");
goto fail_0;
}
if (!PyMapping_Check(env)) {
! PyErr_SetString(PyExc_TypeError, "execve() arg 3 must be a mapping object");
goto fail_0;
}
--- 2315,2325 ----
}
else {
! PyErr_SetString(PyExc_TypeError,
! "execve() arg 2 must be a tuple or list");
goto fail_0;
}
if (!PyMapping_Check(env)) {
! PyErr_SetString(PyExc_TypeError,
! "execve() arg 3 must be a mapping object");
goto fail_0;
}
***************
*** 2348,2351 ****
--- 2350,2355 ----
i = PyMapping_Size(env);
+ if (i < 0)
+ goto fail_1;
envlist = PyMem_NEW(char *, i + 1);
if (envlist == NULL) {
***************
*** 2358,2361 ****
--- 2362,2370 ----
if (!keys || !vals)
goto fail_2;
+ if (!PyList_Check(keys) || !PyList_Check(vals)) {
+ PyErr_SetString(PyExc_TypeError,
+ "execve(): env.keys() or env.values() is not a list");
+ goto fail_2;
+ }
for (pos = 0; pos < i; pos++) {
***************
*** 2368,2373 ****
goto fail_2;
! if (!PyArg_Parse(key, "s;execve() arg 3 contains a non-string key", &k) ||
! !PyArg_Parse(val, "s;execve() arg 3 contains a non-string value", &v))
{
goto fail_2;
--- 2377,2388 ----
goto fail_2;
! if (!PyArg_Parse(
! key,
! "s;execve() arg 3 contains a non-string key",
! &k) ||
! !PyArg_Parse(
! val,
! "s;execve() arg 3 contains a non-string value",
! &v))
{
goto fail_2;
***************
*** 2403,2415 ****
(void) posix_error();
! fail_2:
while (--envc >= 0)
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
! fail_1:
! free_string_array(argvlist,lastarg);
Py_XDECREF(vals);
Py_XDECREF(keys);
! fail_0:
PyMem_Free(path);
return NULL;
--- 2418,2430 ----
(void) posix_error();
! fail_2:
while (--envc >= 0)
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
! fail_1:
! free_string_array(argvlist, lastarg);
Py_XDECREF(vals);
Py_XDECREF(keys);
! fail_0:
PyMem_Free(path);
return NULL;
***************
*** 2453,2457 ****
}
else {
! PyErr_SetString(PyExc_TypeError, "spawnv() arg 2 must be a tuple or list");
PyMem_Free(path);
return NULL;
--- 2468,2473 ----
}
else {
! PyErr_SetString(PyExc_TypeError,
! "spawnv() arg 2 must be a tuple or list");
PyMem_Free(path);
return NULL;
***************
*** 2468,2473 ****
&argvlist[i])) {
free_string_array(argvlist, i);
! PyErr_SetString(PyExc_TypeError,
! "spawnv() arg 2 must contain only strings");
PyMem_Free(path);
return NULL;
--- 2484,2490 ----
&argvlist[i])) {
free_string_array(argvlist, i);
! PyErr_SetString(
! PyExc_TypeError,
! "spawnv() arg 2 must contain only strings");
PyMem_Free(path);
return NULL;
***************
*** 2542,2550 ****
}
else {
! PyErr_SetString(PyExc_TypeError, "spawnve() arg 2 must be a tuple or list");
goto fail_0;
}
if (!PyMapping_Check(env)) {
! PyErr_SetString(PyExc_TypeError, "spawnve() arg 3 must be a mapping object");
goto fail_0;
}
--- 2559,2569 ----
}
else {
! PyErr_SetString(PyExc_TypeError,
! "spawnve() arg 2 must be a tuple or list");
goto fail_0;
}
if (!PyMapping_Check(env)) {
! PyErr_SetString(PyExc_TypeError,
! "spawnve() arg 3 must be a mapping object");
goto fail_0;
}
***************
*** 2557,2561 ****
for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i),
! "et;spawnve() arg 2 must contain only strings",
Py_FileSystemDefaultEncoding,
&argvlist[i]))
--- 2576,2580 ----
for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i),
! "et;spawnve() arg 2 must contain only strings",
Py_FileSystemDefaultEncoding,
&argvlist[i]))
***************
*** 2569,2572 ****
--- 2588,2593 ----
i = PyMapping_Size(env);
+ if (i < 0)
+ goto fail_1;
envlist = PyMem_NEW(char *, i + 1);
if (envlist == NULL) {
***************
*** 2579,2582 ****
--- 2600,2608 ----
if (!keys || !vals)
goto fail_2;
+ if (!PyList_Check(keys) || !PyList_Check(vals)) {
+ PyErr_SetString(PyExc_TypeError,
+ "spawnve(): env.keys() or env.values() is not a list");
+ goto fail_2;
+ }
for (pos = 0; pos < i; pos++) {
***************
*** 2589,2594 ****
goto fail_2;
! if (!PyArg_Parse(key, "s;spawnve() arg 3 contains a non-string key", &k) ||
! !PyArg_Parse(val, "s;spawnve() arg 3 contains a non-string value", &v))
{
goto fail_2;
--- 2615,2626 ----
goto fail_2;
! if (!PyArg_Parse(
! key,
! "s;spawnve() arg 3 contains a non-string key",
! &k) ||
! !PyArg_Parse(
! val,
! "s;spawnve() arg 3 contains a non-string value",
! &v))
{
goto fail_2;
***************
*** 2627,2635 ****
#endif
! fail_2:
while (--envc >= 0)
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
! fail_1:
free_string_array(argvlist, lastarg);
Py_XDECREF(vals);
--- 2659,2667 ----
#endif
! fail_2:
while (--envc >= 0)
PyMem_DEL(envlist[envc]);
PyMem_DEL(envlist);
! fail_1:
free_string_array(argvlist, lastarg);
Py_XDECREF(vals);