]> granicus.if.org Git - python/commitdiff
fix use after free (closes #24552)
authorBenjamin Peterson <benjamin@python.org>
Thu, 2 Jul 2015 21:18:38 +0000 (16:18 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 2 Jul 2015 21:18:38 +0000 (16:18 -0500)
Lib/test/pickletester.py
Misc/NEWS
Modules/_pickle.c

index 2c496d09592aac7ec70f90bcc01ae038835b5668..1682ab151dbe237ea5ddf927263a134fd8225f5b 100644 (file)
@@ -1039,6 +1039,18 @@ class AbstractPickleTests(unittest.TestCase):
                 self.assertEqual(B(x), B(y), detail)
                 self.assertEqual(x.__dict__, y.__dict__, detail)
 
+    def test_newobj_not_class(self):
+        # Issue 24552
+        global SimpleNewObj
+        save = SimpleNewObj
+        o = object.__new__(SimpleNewObj)
+        b = self.dumps(o, 4)
+        try:
+            SimpleNewObj = 42
+            self.assertRaises((TypeError, pickle.UnpicklingError), self.loads, b)
+        finally:
+            SimpleNewObj = save
+
     # Register a type with copyreg, with extension code extcode.  Pickle
     # an object of that type.  Check that the resulting pickle uses opcode
     # (EXT[124]) under proto 2, and not in proto 1.
index 1ed181df1293d64c3204f7d38ceff8f59623ebea..becb9ef1937ea892c54a228b8eb87881a920a338 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -64,6 +64,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #24552: Fix use after free in an error case of the _pickle module.
+
 - Issue #24514: tarfile now tolerates number fields consisting of only
   whitespace.
 
index 19a1c88bd1d1a55d2ca33370aab8a7ef5d440b88..9f16b4d081019a9078cbf641f20aab75ea043529 100644 (file)
@@ -5210,10 +5210,10 @@ load_newobj_ex(UnpicklerObject *self)
     if (!PyType_Check(cls)) {
         Py_DECREF(kwargs);
         Py_DECREF(args);
-        Py_DECREF(cls);
         PyErr_Format(st->UnpicklingError,
                      "NEWOBJ_EX class argument must be a type, not %.200s",
                      Py_TYPE(cls)->tp_name);
+        Py_DECREF(cls);
         return -1;
     }