tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed

the kwlist vector whenever there was a mix of positional and keyword
arguments, and the number of positional arguments exceeded the length
of the kwlist vector.  If there was just one more positional arg than
keyword, the kwlist-terminating NULL got passed to PyMapping_HasKeyString,
which set an internal error that vgetargskeywords() then squashed (but
it's impossible to say whether it knew it was masking an error).  If
more than one more positional argument, it went on to pass random trash
to PyMapping_HasKeyString, which is why the example at the start
happened to kill the process.

Pure bugfix candidate.
This commit is contained in:
Tim Peters 2001-10-27 00:46:09 +00:00
parent f4331c1c38
commit a9f4739a1b
1 changed files with 13 additions and 3 deletions

View File

@ -1083,18 +1083,28 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
/* make sure there are no duplicate values for an argument;
its not clear when to use the term "keyword argument vs.
keyword parameter in messages */
if (keywords) {
for (i = 0; i < tplen; i++) {
if (PyMapping_HasKeyString(keywords, kwlist[i])) {
char *thiskw = kwlist[i];
if (thiskw == NULL)
break;
if (PyMapping_HasKeyString(keywords, thiskw)) {
sprintf(msgbuf,
"keyword parameter %s redefined",
kwlist[i]);
thiskw);
PyErr_SetString(PyExc_TypeError, msgbuf);
return 0;
}
}
}
/* XXX The loop just above didn't used to break when hitting the
end of kwlist, so could pass NULL on to PyMapping_HasKeyString,
which sets a "NULL argument to internal routine" error then.
However, the comment below doesn't give any clues about which
'error string' it's talking about, so darned hard to say whether
the PyErr_Clear() still serves a purpose.
*/
PyErr_Clear(); /* I'm not which Py functions set the error string */
/* required arguments missing from args can be supplied by keyword