Skip to content

Commit

Permalink
rearrange methodcaller_new so that the main error case does not cause…
Browse files Browse the repository at this point in the history
… uninitialized memory usage (closes #27783)
  • Loading branch information
benjaminp committed Aug 17, 2016
1 parent 3a27b08 commit 1f0e7c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Misc/NEWS
Expand Up @@ -29,6 +29,8 @@ Core and Builtins
Library
-------

- Issue #27783: Fix possible usage of uninitialized memory in operator.methodcaller.

- Issue #27774: Fix possible Py_DECREF on unowned object in _sre.

- Issue #27760: Fix possible integer overflow in binascii.b2a_qp.
Expand Down
15 changes: 7 additions & 8 deletions Modules/operator.c
Expand Up @@ -776,7 +776,7 @@ static PyObject *
methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
methodcallerobject *mc;
PyObject *name, *newargs;
PyObject *name;

if (PyTuple_GET_SIZE(args) < 1) {
PyErr_SetString(PyExc_TypeError, "methodcaller needs at least "
Expand All @@ -789,20 +789,19 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (mc == NULL)
return NULL;

newargs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
if (newargs == NULL) {
Py_DECREF(mc);
return NULL;
}
mc->args = newargs;

name = PyTuple_GET_ITEM(args, 0);
Py_INCREF(name);
mc->name = name;

Py_XINCREF(kwds);
mc->kwds = kwds;

mc->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
if (mc->args == NULL) {
Py_DECREF(mc);
return NULL;
}

PyObject_GC_Track(mc);
return (PyObject *)mc;
}
Expand Down

0 comments on commit 1f0e7c9

Please sign in to comment.