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

Skip to content

Commit cffed4b

Browse files
committed
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
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).
1 parent 42f5332 commit cffed4b

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

Misc/NEWS

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
What's New in Python 2.2c1?
1+
What's New in Python 2.2c1
22
XXX Release date: ??-Dec-2001 XXX
33
===========================
44

@@ -22,6 +22,13 @@ Build
2222

2323
C API
2424

25+
- PyArg_ParseTupleAndKeywords() requires that the number of entries in
26+
the keyword list equals the number of argument specifiers. This
27+
wasn't checked correctly, and PyArg_ParseTupleAndKeywords could even
28+
dump core in some bad cases. This has been repaired. As a result,
29+
PyArg_ParseTupleAndKeywords may raise RuntimeError in bad cases that
30+
previously went unchallenged.
31+
2532
New platforms
2633

2734
Tests

Python/getargs.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
10491049

10501050
/* Search the format:
10511051
message <- error msg, if any (else NULL).
1052-
name <- routine name, if any (else NULL).
1052+
fname <- routine name, if any (else NULL).
10531053
min <- # of required arguments, or -1 if all are required.
10541054
max <- most arguments (required + optional).
10551055
Check that kwlist has a non-NULL entry for each arg.
@@ -1064,8 +1064,9 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
10641064
if (isalpha(i) && i != 'e') {
10651065
max++;
10661066
if (*p == NULL) {
1067-
/* kwlist is too short */
1068-
PyErr_BadInternalCall();
1067+
PyErr_SetString(PyExc_RuntimeError,
1068+
"more argument specifiers than "
1069+
"keyword list entries");
10691070
return 0;
10701071
}
10711072
p++;
@@ -1081,15 +1082,17 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
10811082
break;
10821083
}
10831084
else if (i == '(') {
1084-
PyErr_SetString(PyExc_SystemError,
1085-
"tuple found in format when using keyword arguments");
1085+
PyErr_SetString(PyExc_RuntimeError,
1086+
"tuple found in format when using keyword "
1087+
"arguments");
10861088
return 0;
10871089
}
10881090
}
10891091
format = formatsave;
10901092
if (*p != NULL) {
1091-
/* kwlist is too long */
1092-
PyErr_BadInternalCall();
1093+
PyErr_SetString(PyExc_RuntimeError,
1094+
"more keyword list entries than "
1095+
"argument specifiers");
10931096
return 0;
10941097
}
10951098
if (min < 0) {

0 commit comments

Comments
 (0)