]> granicus.if.org Git - python/commitdiff
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 18 Oct 2002 16:33:13 +0000 (16:33 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 18 Oct 2002 16:33:13 +0000 (16:33 +0000)
Don't crash when getting value of a property raises an exception

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

index c9bd1cd7d43d7534ce36046dc2fc5ad4d8acf48c..7573bfd9a0f0cf33fa982d37604965f9fd1f5431 100644 (file)
@@ -1814,6 +1814,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 ed5b82951ae163eb000c3d2067dd7d571c701be9..e624ec4da33d688ac27b2f030b997ec70bc98e4f 100644 (file)
@@ -3145,8 +3145,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);