[Python-checkins] cpython (3.3): rearrange methodcaller_new so that the main error case does not cause

benjamin.peterson python-checkins at python.org
Wed Aug 17 02:37:56 EDT 2016


https://hg.python.org/cpython/rev/8e3b9bf917a7
changeset:   102713:8e3b9bf917a7
branch:      3.3
parent:      102689:cbf2a05648b3
user:        Benjamin Peterson <benjamin at python.org>
date:        Tue Aug 16 23:35:35 2016 -0700
summary:
  rearrange methodcaller_new so that the main error case does not cause uninitialized memory usage (closes #27783)

files:
  Misc/NEWS          |   2 ++
  Modules/operator.c |  15 +++++++--------
  2 files changed, 9 insertions(+), 8 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,8 @@
 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.
diff --git a/Modules/operator.c b/Modules/operator.c
--- a/Modules/operator.c
+++ b/Modules/operator.c
@@ -776,7 +776,7 @@
 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 "
@@ -789,13 +789,6 @@
     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;
@@ -803,6 +796,12 @@
     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;
 }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list