]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 18 Oct 2002 16:45:39 +0000 (16:45 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 18 Oct 2002 16:45:39 +0000 (16:45 +0000)
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman

Don't crash when getting value of a property raises an exception

Lib/test/test_descr.py
Objects/typeobject.c

index 74e33499d09393c35939726b7915a3ce8289560b..1544eb37cb5b87bfd673a6e6272a1a0d51840620 100644 (file)
@@ -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..."
 
index 8a1adc914594d5345d4567d12c15f8fdfc67d5d8..db25705c24457320bcf42cbcfd75928fca6f5b5b 100644 (file)
@@ -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);