]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport checkin:
authorWalter Dörwald <walter@livinglogic.de>
Mon, 18 Aug 2003 18:34:09 +0000 (18:34 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Mon, 18 Aug 2003 18:34:09 +0000 (18:34 +0000)
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().

Python/bltinmodule.c

index 49fcc09cfc04a1cfab40a31fabcbaf04b3616f02..e10d16ba65f416742f4c5828ffec838bbd7977f6 100644 (file)
@@ -2176,6 +2176,8 @@ filtertuple(PyObject *func, PyObject *tuple)
                if (tuple->ob_type->tp_as_sequence &&
                    tuple->ob_type->tp_as_sequence->sq_item) {
                        item = tuple->ob_type->tp_as_sequence->sq_item(tuple, i);
+                       if (item == NULL)
+                               goto Fail_1;
                } else {
                        PyErr_SetString(PyExc_TypeError, "filter(): unsubscriptable tuple");
                        goto Fail_1;
@@ -2186,20 +2188,25 @@ filtertuple(PyObject *func, PyObject *tuple)
                }
                else {
                        PyObject *arg = Py_BuildValue("(O)", item);
-                       if (arg == NULL)
+                       if (arg == NULL) {
+                               Py_DECREF(item);
                                goto Fail_1;
+                       }
                        good = PyEval_CallObject(func, arg);
                        Py_DECREF(arg);
-                       if (good == NULL)
+                       if (good == NULL) {
+                               Py_DECREF(item);
                                goto Fail_1;
+                       }
                }
                ok = PyObject_IsTrue(good);
                Py_DECREF(good);
                if (ok) {
-                       Py_INCREF(item);
                        if (PyTuple_SetItem(result, j++, item) < 0)
                                goto Fail_1;
                }
+               else
+                       Py_DECREF(item);
        }
 
        if (_PyTuple_Resize(&result, j) < 0)