Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4ad37e

Browse files
committed
Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Patch by Serhiy Storchaka.
1 parent 9f69e79 commit e4ad37e

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

Lib/test/test_select.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def test_select(self):
4949
self.fail('Unexpected return values from select():', rfd, wfd, xfd)
5050
p.close()
5151

52+
# Issue 16230: Crash on select resized list
53+
def test_select_mutated(self):
54+
a = []
55+
class F:
56+
def fileno(self):
57+
del a[-1]
58+
return sys.__stdout__.fileno()
59+
a[:] = [F()] * 10
60+
self.assertEqual(select.select([], a, []), ([], a[:5], []))
61+
5262
def test_main():
5363
support.run_unittest(SelectTestCase)
5464
support.reap_children()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ Core and Builtins
143143
Library
144144
-------
145145

146+
- Issue #16230: Fix a crash in select.select() when one the lists changes
147+
size while iterated on. Patch by Serhiy Storchaka.
148+
146149
- Issue #16228: Fix a crash in the json module where a list changes size
147150
while it is being encoded. Patch by Serhiy Storchaka.
148151

Modules/selectmodule.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
8383
{
8484
int max = -1;
8585
int index = 0;
86-
Py_ssize_t i, len = -1;
86+
Py_ssize_t i;
8787
PyObject* fast_seq = NULL;
8888
PyObject* o = NULL;
8989

@@ -94,9 +94,7 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
9494
if (!fast_seq)
9595
return -1;
9696

97-
len = PySequence_Fast_GET_SIZE(fast_seq);
98-
99-
for (i = 0; i < len; i++) {
97+
for (i = 0; i < PySequence_Fast_GET_SIZE(fast_seq); i++) {
10098
SOCKET v;
10199

102100
/* any intervening fileno() calls could decr this refcnt */

0 commit comments

Comments
 (0)