Kaydet (Commit) c3858bd7 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #29360: _PyStack_AsDict() doesn't check kwnames

Remove two assertions which can fail on legit code. Keyword arguments are
checked later with better tests and raise a regular (TypeError) exception.
üst 90f63323
...@@ -166,13 +166,16 @@ PyAPI_FUNC(PyObject*) _PyStack_AsTupleSlice( ...@@ -166,13 +166,16 @@ PyAPI_FUNC(PyObject*) _PyStack_AsTupleSlice(
Py_ssize_t start, Py_ssize_t start,
Py_ssize_t end); Py_ssize_t end);
/* Convert keyword arguments from the (stack, kwnames) format to a Python /* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)
dictionary. format to a Python dictionary ("kwargs" dict).
kwnames must only contains str strings, no subclass, and all keys must be The type of kwnames keys is not checked. The final function getting
unique. kwnames is not checked, usually these checks are done before or arguments is reponsible to check if all keys are strings, for example using
later calling _PyStack_AsDict(). For example, _PyArg_ParseStackAndKeywords() raises an PyArg_ParseTupleAndKeywords() or PyArg_ValidateKeywordArguments().
error if a key is not a string. */
Duplicate keys are merged using the last value. If duplicate keys must raise
an exception, the caller is responsible to implement an explicit keys on
kwnames. */
PyAPI_FUNC(PyObject *) _PyStack_AsDict( PyAPI_FUNC(PyObject *) _PyStack_AsDict(
PyObject **values, PyObject **values,
PyObject *kwnames); PyObject *kwnames);
......
...@@ -2413,8 +2413,7 @@ _PyStack_AsDict(PyObject **values, PyObject *kwnames) ...@@ -2413,8 +2413,7 @@ _PyStack_AsDict(PyObject **values, PyObject *kwnames)
for (i = 0; i < nkwargs; i++) { for (i = 0; i < nkwargs; i++) {
PyObject *key = PyTuple_GET_ITEM(kwnames, i); PyObject *key = PyTuple_GET_ITEM(kwnames, i);
PyObject *value = *values++; PyObject *value = *values++;
assert(PyUnicode_CheckExact(key)); /* If key already exists, replace it with the new value */
assert(PyDict_GetItem(kwdict, key) == NULL);
if (PyDict_SetItem(kwdict, key, value)) { if (PyDict_SetItem(kwdict, key, value)) {
Py_DECREF(kwdict); Py_DECREF(kwdict);
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment