[Python-checkins] cpython (2.7): Issue #16230: Fix a crash in select.select() when one the lists changes size
antoine.pitrou
python-checkins at python.org
Thu Nov 1 20:20:37 CET 2012
http://hg.python.org/cpython/rev/02a5322b0cee
changeset: 80164:02a5322b0cee
branch: 2.7
parent: 80160:33ae62a4ecf5
user: Antoine Pitrou <solipsis at pitrou.net>
date: Thu Nov 01 20:13:54 2012 +0100
summary:
Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Patch by Serhiy Storchaka.
files:
Lib/test/test_select.py | 9 +++++++++
Misc/NEWS | 3 +++
Modules/selectmodule.c | 5 +----
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/Lib/test/test_select.py b/Lib/test/test_select.py
--- a/Lib/test/test_select.py
+++ b/Lib/test/test_select.py
@@ -49,6 +49,15 @@
self.fail('Unexpected return values from select():', rfd, wfd, xfd)
p.close()
+ # Issue 16230: Crash on select resized list
+ def test_select_mutated(self):
+ a = []
+ class F:
+ def fileno(self):
+ del a[-1]
+ return sys.__stdout__.fileno()
+ a[:] = [F()] * 10
+ self.assertEqual(select.select([], a, []), ([], a[:5], []))
def test_main():
test_support.run_unittest(SelectTestCase)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -130,6 +130,9 @@
Library
-------
+- Issue #16230: Fix a crash in select.select() when one the lists changes
+ size while iterated on. Patch by Serhiy Storchaka.
+
- Issue #16228: Fix a crash in the json module where a list changes size
while it is being encoded. Patch by Serhiy Storchaka.
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -87,7 +87,6 @@
int i;
int max = -1;
int index = 0;
- int len = -1;
PyObject* fast_seq = NULL;
PyObject* o = NULL;
@@ -98,9 +97,7 @@
if (!fast_seq)
return -1;
- len = PySequence_Fast_GET_SIZE(fast_seq);
-
- for (i = 0; i < len; i++) {
+ for (i = 0; i < PySequence_Fast_GET_SIZE(fast_seq); i++) {
SOCKET v;
/* any intervening fileno() calls could decr this refcnt */
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list