summaryrefslogtreecommitdiff
path: root/Modules/_operator.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 15:05:40 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 15:05:40 -0800
commitb2fa705fd3887c326e811c418469c784353027f4 (patch)
treeb3428f73de91453edbfd4df1a5d4a212d182eb44 /Modules/_operator.c
parent134e58fd3aaa2e91390041e143f3f0a21a60142b (diff)
parentb53654b6dbfce8318a7d4d1cdaddca7a7fec194b (diff)
downloadcpython-b2fa705fd3887c326e811c418469c784353027f4.tar.gz
Issue #29392: Prevent crash when passing invalid arguments into msvcrt module.
Diffstat (limited to 'Modules/_operator.c')
-rw-r--r--Modules/_operator.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/Modules/_operator.c b/Modules/_operator.c
index dfff1d2faa..fb8eafc679 100644
--- a/Modules/_operator.c
+++ b/Modules/_operator.c
@@ -1111,6 +1111,8 @@ methodcaller_reduce(methodcallerobject *mc)
PyObject *functools;
PyObject *partial;
PyObject *constructor;
+ PyObject *newargs[2];
+
_Py_IDENTIFIER(partial);
functools = PyImport_ImportModule("functools");
if (!functools)
@@ -1119,17 +1121,11 @@ methodcaller_reduce(methodcallerobject *mc)
Py_DECREF(functools);
if (!partial)
return NULL;
- newargs = PyTuple_New(2);
- if (newargs == NULL) {
- Py_DECREF(partial);
- return NULL;
- }
- Py_INCREF(Py_TYPE(mc));
- PyTuple_SET_ITEM(newargs, 0, (PyObject *)Py_TYPE(mc));
- Py_INCREF(mc->name);
- PyTuple_SET_ITEM(newargs, 1, mc->name);
- constructor = PyObject_Call(partial, newargs, mc->kwds);
- Py_DECREF(newargs);
+
+ newargs[0] = (PyObject *)Py_TYPE(mc);
+ newargs[1] = mc->name;
+ constructor = _PyObject_FastCallDict(partial, newargs, 2, mc->kwds);
+
Py_DECREF(partial);
return Py_BuildValue("NO", constructor, mc->args);
}