8000 rearrange methodcaller_new so that the main error case does not cause… · stackless-dev/stackless@1f0e7c9 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 1f0e7c9

Browse files
committed
rearrange methodcaller_new so that the main error case does not cause uninitialized memory usage (closes python#27783)
1 parent 3a27b08 commit 1f0e7c9

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Core and Builtins
2929
Library
3030
-------
3131

32+
- Issue #27783: Fix possible usage of uninitialized memory in operator.methodcaller.
33+
3234
- Issue #27774: Fix possible Py_DECREF on unowned object in _sre.
3335

3436
- Issue #27760: Fix possible integer overflow in binascii.b2a_qp.

Modules/operator.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ static PyObject *
776776
methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
777777
{
778778
methodcallerobject *mc;
779-
PyObject *name, *newargs;
779+
PyObject *name;
780780

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

792-
newargs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
793-
if (newargs == NULL) {
794-
Py_DECREF(mc);
795-
return NULL;
796-
}
797-
mc->args = newargs;
798-
799792
name = PyTuple_GET_ITEM(args, 0);
800793
Py_INCREF(name);
801794
mc->name = name;
802795

803796
Py_XINCREF(kwds);
804797
mc->kwds = kwds;
805798

799+
mc->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
800+
if (mc->args == NULL) {
801+
Py_DECREF(mc);
802+
return NULL;
803+
}
804+
806805
PyObject_GC_Track(mc);
807806
return (PyObject *)mc;
808807
}

0 commit comments

Comments
 (0)
0