Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c58a3a1

Browse files
committed
Fix a crash: when sq_item failed the code continued blindly and used the
NULL pointer. (Detected by Michael Hudson, patch provided by Neal Norwitz). Fix refcounting leak in filtertuple().
1 parent 6019f9a commit c58a3a1

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

Python/bltinmodule.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,8 @@ filtertuple(PyObject *func, PyObject *tuple)
21742174
if (tuple->ob_type->tp_as_sequence &&
21752175
tuple->ob_type->tp_as_sequence->sq_item) {
21762176
item = tuple->ob_type->tp_as_sequence->sq_item(tuple, i);
2177+
if (item == NULL)
2178+
goto Fail_1;
21772179
} else {
21782180
PyErr_SetString(PyExc_TypeError, "filter(): unsubscriptable tuple");
21792181
goto Fail_1;
@@ -2184,20 +2186,25 @@ filtertuple(PyObject *func, PyObject *tuple)
21842186
}
21852187
else {
21862188
PyObject *arg = Py_BuildValue("(O)", item);
2187-
if (arg == NULL)
2189+
if (arg == NULL) {
2190+
Py_DECREF(item);
21882191
goto Fail_1;
2192+
}
21892193
good = PyEval_CallObject(func, arg);
21902194
Py_DECREF(arg);
2191-
if (good == NULL)
2195+
if (good == NULL) {
2196+
Py_DECREF(item);
21922197
goto Fail_1;
2198+
}
21932199
}
21942200
ok = PyObject_IsTrue(good);
21952201
Py_DECREF(good);
21962202
if (ok) {
2197-
Py_INCREF(item);
21982203
if (PyTuple_SetItem(result, j++, item) < 0)
21992204
goto Fail_1;
22002205
}
2206+
else
2207+
Py_DECREF(item);
22012208
}
22022209

22032210
if (_PyTuple_Resize(&result, j) < 0)

0 commit comments

Comments
 (0)