]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
authorTim Peters <tim.peters@gmail.com>
Sat, 27 Oct 2001 03:58:40 +0000 (03:58 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 27 Oct 2001 03:58:40 +0000 (03:58 +0000)
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.

Python/getargs.c

index 451b9140c6668e60ac9d43419ffe5bf53ad91560..840bf51d25c6a2a956ad5f5e2d347e6ef2ae17cc 100644 (file)
@@ -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 (;;) {