summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-10-27 03:58:40 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-10-27 03:58:40 (GMT)
commit45772cde7e6d936cb37a4762eba3ca23c0b1c667 (patch)
treed808640b773682c0ac4367fc69e6b977f1f79844
parenta9f4739a1b315417d5b79055a64ee8dd11d1b173 (diff)
downloadcpython-45772cde7e6d936cb37a4762eba3ca23c0b1c667.zip
cpython-45772cde7e6d936cb37a4762eba3ca23c0b1c667.tar.gz
cpython-45772cde7e6d936cb37a4762eba3ca23c0b1c667.tar.bz2
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
and raise an error if they're insane. vgetargskeywords: the same, except that since this is an internal routine, just assert that the arguments are sane.
-rw-r--r--Python/getargs.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 451b914..840bf51 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1005,7 +1005,16 @@ PyArg_ParseTupleAndKeywords(PyObject *args,
{
int retval;
va_list va;
-
+
+ if ((args == NULL || !PyTuple_Check(args)) ||
+ (keywords != NULL && !PyDict_Check(keywords)) ||
+ format == NULL ||
+ kwlist == NULL)
+ {
+ PyErr_BadInternalCall();
+ return -1;
+ }
+
va_start(va, kwlist);
retval = vgetargskeywords(args, keywords, format, kwlist, &va);
va_end(va);
@@ -1029,6 +1038,12 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
int nkwds, pos, match, converted;
PyObject *key, *value;
+ assert(args != NULL && PyTuple_Check(args));
+ assert(keywords == NULL || PyDict_Check(keywords));
+ assert(format != NULL);
+ assert(kwlist != NULL);
+ assert(p_va != NULL);
+
/* nested tuples cannot be parsed when using keyword arguments */
for (;;) {