]> granicus.if.org Git - python/commitdiff
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
authorTim Peters <tim.peters@gmail.com>
Thu, 29 Nov 2001 03:26:37 +0000 (03:26 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 29 Nov 2001 03:26:37 +0000 (03:26 +0000)
vgetargskeywords():  Now that this routine is checking for bad input
(rather than dump core in some cases), some bad calls are raising errors
that previously "worked".  This patch makes the error strings more
revealing, and changes the exceptions from SystemError to RuntimeError
(under the theory that SystemError is more of a "can't happen!" assert-
like thing, and so inappropriate for bad arguments to a public C API
function).

Misc/NEWS
Python/getargs.c

index 161be54464ec04604c53c534efb889100ddddb5e..5bb35085b6e05cf027049db05050c2e492cef80a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1,4 +1,4 @@
-What's New in Python 2.2c1?
+What's New in Python 2.2c1
 XXX Release date: ??-Dec-2001 XXX
 ===========================
 
@@ -22,6 +22,13 @@ Build
 
 C API
 
+- PyArg_ParseTupleAndKeywords() requires that the number of entries in
+  the keyword list equals the number of argument specifiers.  This
+  wasn't checked correctly, and PyArg_ParseTupleAndKeywords could even
+  dump core in some bad cases.  This has been repaired.  As a result,
+  PyArg_ParseTupleAndKeywords may raise RuntimeError in bad cases that
+  previously went unchallenged.
+
 New platforms
 
 Tests
index 3a319132d954e78456a5c9a1c2efdbfe9af6b06b..a58816fa865a639f9bf10055ffb836c054a24a0e 100644 (file)
@@ -1049,7 +1049,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
 
        /* Search the format:
           message <- error msg, if any (else NULL).
-          name <- routine name, if any (else NULL).
+          fname <- routine name, if any (else NULL).
           min <- # of required arguments, or -1 if all are required.
           max <- most arguments (required + optional).
           Check that kwlist has a non-NULL entry for each arg.
@@ -1064,8 +1064,9 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
                if (isalpha(i) && i != 'e') {
                        max++;
                        if (*p == NULL) {
-                               /* kwlist is too short */
-                               PyErr_BadInternalCall();
+                               PyErr_SetString(PyExc_RuntimeError,
+                                       "more argument specifiers than "
+                                       "keyword list entries");
                                return 0;
                        }
                        p++;
@@ -1081,15 +1082,17 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
                        break;
                }
                else if (i == '(') {
-                       PyErr_SetString(PyExc_SystemError,
-                     "tuple found in format when using keyword arguments");
+                       PyErr_SetString(PyExc_RuntimeError,
+                               "tuple found in format when using keyword "
+                               "arguments");
                        return 0;
                }
        }
        format = formatsave;
        if (*p != NULL) {
-               /* kwlist is too long */
-               PyErr_BadInternalCall();
+               PyErr_SetString(PyExc_RuntimeError,
+                       "more keyword list entries than "
+                       "argument specifiers");
                return 0;
        }
        if (min < 0) {