]> granicus.if.org Git - python/commitdiff
Issue #16230: Fix a crash in select.select() when one the lists changes size while...
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 1 Nov 2012 19:13:54 +0000 (20:13 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 1 Nov 2012 19:13:54 +0000 (20:13 +0100)
Patch by Serhiy Storchaka.

Lib/test/test_select.py
Misc/NEWS
Modules/selectmodule.c

index 79b249bf411033d5ff8431d98fbbd3520767a4e8..175bbdac500fe179e89791b941ef2a253b34be6c 100644 (file)
@@ -49,6 +49,15 @@ class SelectTestCase(unittest.TestCase):
             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)
index 3c9ffc0bce03dc15d699af7e5082b9ba5080060b..139216f83b52e83e02e85e51106fceea54412d1a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -130,6 +130,9 @@ Core and Builtins
 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.
 
index 5a8580c8ac92381ed367ba9bd0013f9dd1be2e37..b95b2cedc175cab4ebbe09bfd5e15e12d1c4829a 100644 (file)
@@ -87,7 +87,6 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
     int i;
     int max = -1;
     int index = 0;
-    int len = -1;
     PyObject* fast_seq = NULL;
     PyObject* o = NULL;
 
@@ -98,9 +97,7 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
     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 */