From: Neal Norwitz Date: Fri, 18 Oct 2002 16:45:39 +0000 (+0000) Subject: Backport: X-Git-Tag: v2.2.3c1~288 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=96a85300f61c8b08707a490f3ec5b18d16072232;p=thirdparty%2FPython%2Fcpython.git Backport: Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman Don't crash when getting value of a property raises an exception --- diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 74e33499d093..1544eb37cb5b 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1683,6 +1683,18 @@ def properties(): raise TestFailed("expected TypeError from trying to set " "readonly %r attr on a property" % attr) + class D(object): + __getitem__ = property(lambda s: 1/0) + + d = D() + try: + for i in d: + str(i) + except ZeroDivisionError: + pass + else: + raise TestFailed, "expected ZeroDivisionError from bad property" + def supers(): if verbose: print "Testing super..." diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 8a1adc914594..db25705c2445 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2918,8 +2918,12 @@ slot_sq_item(PyObject *self, int i) if (func != NULL) { if ((f = func->ob_type->tp_descr_get) == NULL) Py_INCREF(func); - else + else { func = f(func, self, (PyObject *)(self->ob_type)); + if (func == NULL) { + return NULL; + } + } ival = PyInt_FromLong(i); if (ival != NULL) { args = PyTuple_New(1);