Skip to content

Commit b0ffe74

Browse files
committed
Fix a heap buffer overflow in partial_repr
1 parent 0e7c06a commit b0ffe74

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Modules/_functoolsmodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ partial_repr(PyObject *self)
693693
PyObject *name;
694694
Py_ssize_t i, n;
695695
PyObject *key, *value;
696+
PyObject* args;
696697
int status;
697698

698699
status = Py_ReprEnter(self);
@@ -707,13 +708,15 @@ partial_repr(PyObject *self)
707708
goto done;
708709
/* Pack positional arguments */
709710
assert(PyTuple_Check(pto->args));
711+
args = Py_NewRef(pto->args);
710712
n = PyTuple_GET_SIZE(pto->args);
711713
for (i = 0; i < n; i++) {
712714
Py_SETREF(arglist, PyUnicode_FromFormat("%U, %R", arglist,
713-
PyTuple_GET_ITEM(pto->args, i)));
715+
PyTuple_GET_ITEM(args, i)));
714716
if (arglist == NULL)
715717
goto done;
716718
}
719+
Py_DECREF(args);
717720
/* Pack keyword arguments */
718721
assert (PyDict_Check(pto->kw));
719722
for (i = 0; PyDict_Next(pto->kw, &i, &key, &value);) {

0 commit comments

Comments
 (0)