]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)
authorOran Avraham <252748+oranav@users.noreply.github.com>
Wed, 5 Dec 2018 20:36:03 +0000 (22:36 +0200)
committerVictor Stinner <vstinner@redhat.com>
Wed, 5 Dec 2018 20:36:03 +0000 (21:36 +0100)
select() calls are retried on EINTR (per PEP 475).  However, if a
timeout was provided and the deadline has passed after running the
signal handlers, rlist, wlist and xlist should be cleared since select(2)
left them unmodified.

Misc/NEWS.d/next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst [new file with mode: 0644]
Modules/selectmodule.c

diff --git a/Misc/NEWS.d/next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst b/Misc/NEWS.d/next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst
new file mode 100644 (file)
index 0000000..1ab2e16
--- /dev/null
@@ -0,0 +1,4 @@
+Fix a bug in :func:`select.select` where, in some cases, the file descriptor
+sequences were returned unmodified after a signal interruption, even though the
+file descriptors might not be ready yet.  :func:`select.select` will now always
+return empty lists if a timeout has occurred.  Patch by Oran Avraham.
index 5a6b13466c8061576e11248a4ad493c25d8c62c3..fe69cd58dc6a28ea43fbdef6fcb2d654263be2e5 100644 (file)
@@ -335,6 +335,10 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
         if (tvp) {
             timeout = deadline - _PyTime_GetMonotonicClock();
             if (timeout < 0) {
+                /* bpo-35310: lists were unmodified -- clear them explicitly */
+                FD_ZERO(&ifdset);
+                FD_ZERO(&ofdset);
+                FD_ZERO(&efdset);
                 n = 0;
                 break;
             }