]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix possible double free in TextIOWrapper.__init__ (closes #22849)
authorBenjamin Peterson <benjamin@python.org>
Wed, 12 Nov 2014 15:19:46 +0000 (10:19 -0500)
committerBenjamin Peterson <benjamin@python.org>
Wed, 12 Nov 2014 15:19:46 +0000 (10:19 -0500)
Lib/test/test_io.py
Misc/NEWS
Modules/_io/textio.c

index b5506b0ac49ecdaf111b8e282255cf9db634e5d2..940e921e54d2ae712ebab5a71fa51262d4238169 100644 (file)
@@ -2784,6 +2784,21 @@ class TextIOWrapperTest(unittest.TestCase):
         self.assertFalse(err)
         self.assertEqual("ok", out.decode().strip())
 
+    def test_issue22849(self):
+        class F(object):
+            def readable(self): return True
+            def writable(self): return True
+            def seekable(self): return True
+
+        for i in range(10):
+            try:
+                self.TextIOWrapper(F(), encoding='utf-8')
+            except Exception:
+                pass
+
+        F.tell = lambda x: 0
+        t = self.TextIOWrapper(F(), encoding='utf-8')
+
 
 class CTextIOWrapperTest(TextIOWrapperTest):
     io = io
index 7331e990668c56b5966419d515d3d7eb4f66fe39..bb58965623557f26207f95b86592bbc5d965fc12 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #22849: Fix possible double free in the io.TextIOWrapper constructor.
+
 - Issue #12728: Different Unicode characters having the same uppercase but
   different lowercase are now matched in case-insensitive regular expressions.
 
index a3e82a8b446f697c29fe60441ddc550ddb7e0edd..4555bf778d3e8428c5bf872c94432477ccc5471a 100644 (file)
@@ -1061,7 +1061,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
     }
 
     /* Finished sorting out the codec details */
-    Py_DECREF(codec_info);
+    Py_CLEAR(codec_info);
 
     self->buffer = buffer;
     Py_INCREF(buffer);