[Zodb-checkins] SVN: ZODB/trunk/src/persistent/ Added a missing type error to void crashes under unlikely situations.

Jim Fulton jim at zope.com
Sat Aug 22 13:46:13 EDT 2009


Log message for revision 103089:
  Added a missing type error to void crashes under unlikely situations.
  

Changed:
  U   ZODB/trunk/src/persistent/cPersistence.c
  U   ZODB/trunk/src/persistent/tests/test_persistent.py

-=-
Modified: ZODB/trunk/src/persistent/cPersistence.c
===================================================================
--- ZODB/trunk/src/persistent/cPersistence.c	2009-08-22 16:08:21 UTC (rev 103088)
+++ ZODB/trunk/src/persistent/cPersistence.c	2009-08-22 17:46:13 UTC (rev 103089)
@@ -474,23 +474,23 @@
       PyObject **dict;
 
       dict = _PyObject_GetDictPtr(self);
-      if (dict)
+      
+      if (!dict)
         {
-          if (!*dict)
-            {
-              *dict = PyDict_New();
-              if (!*dict)
-                return NULL;
-            }
+          PyErr_SetString(PyExc_TypeError,
+                          "this object has no instance dictionary");
+          return NULL;
         }
 
-      if (*dict)
+      if (!*dict)
         {
-          PyDict_Clear(*dict);
-          if (PyDict_Update(*dict, state) < 0)
+          *dict = PyDict_New();
+          if (!*dict)
             return NULL;
         }
-      else if (pickle_setattrs_from_dict(self, state) < 0)
+
+      PyDict_Clear(*dict);
+      if (PyDict_Update(*dict, state) < 0)
         return NULL;
     }
 

Modified: ZODB/trunk/src/persistent/tests/test_persistent.py
===================================================================
--- ZODB/trunk/src/persistent/tests/test_persistent.py	2009-08-22 16:08:21 UTC (rev 103088)
+++ ZODB/trunk/src/persistent/tests/test_persistent.py	2009-08-22 17:46:13 UTC (rev 103089)
@@ -1,16 +1,17 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) Zope Foundation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+import unittest
 from zope.testing import doctest
 from persistent import Persistent
 
@@ -20,5 +21,23 @@
     def inc(self):
         self.x += 1
 
+def cpersistent_setstate_pointer_sanity():
+    """
+    >>> Persistent().__setstate__({})
+    Traceback (most recent call last):
+    ...
+    TypeError: this object has no instance dictionary
+
+    >>> class C(Persistent): __slots__ = 'x', 'y'
+    >>> C().__setstate__(({}, {}))
+    Traceback (most recent call last):
+    ...
+    TypeError: this object has no instance dictionary
+    """
+
+
 def test_suite():
-    return doctest.DocFileSuite("persistent.txt", globs={"P": P})
+    return unittest.TestSuite((
+        doctest.DocFileSuite("persistent.txt", globs={"P": P}),
+        doctest.DocTestSuite(),
+        ))



More information about the Zodb-checkins mailing list