[Python-checkins] cpython (3.4): fix possible double free in TextIOWrapper.__init__ (closes #22849)

benjamin.peterson python-checkins at python.org
Wed Nov 12 16:24:31 CET 2014


https://hg.python.org/cpython/rev/ec1948191461
changeset: 93478:ec1948191461
branch: 3.4
parent: 93473:33908f14c0eb
user: Benjamin Peterson <benjamin at python.org>
date: Wed Nov 12 10:19:46 2014 -0500
summary:
 fix possible double free in TextIOWrapper.__init__ (closes #22849)
files:
 Lib/test/test_io.py | 15 +++++++++++++++
 Misc/NEWS | 2 ++
 Modules/_io/textio.c | 2 +-
 3 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2784,6 +2784,21 @@
 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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,8 @@
 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.
 
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1061,7 +1061,7 @@
 }
 
 /* Finished sorting out the codec details */
- Py_DECREF(codec_info);
+ Py_CLEAR(codec_info);
 
 self->buffer = buffer;
 Py_INCREF(buffer);
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /