summaryrefslogtreecommitdiffstats
path: root/Modules/selectmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-08-20 17:38:21 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-08-20 17:38:21 (GMT)
commitb1973c252c2eec757eaa067afaf593c2cc5ea8db (patch)
treeed78f6f23d427c0dd0ee589c308d1b5cbb297a77 /Modules/selectmodule.c
parentec67d187ee9a86aaf1108643832f69ad3bc0e369 (diff)
downloadcpython-b1973c252c2eec757eaa067afaf593c2cc5ea8db.zip
cpython-b1973c252c2eec757eaa067afaf593c2cc5ea8db.tar.gz
cpython-b1973c252c2eec757eaa067afaf593c2cc5ea8db.tar.bz2
Issue #8865: Concurrent invocation of select.poll.poll() now raises a
RuntimeError exception. Patch by Christian Schubert.
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r--Modules/selectmodule.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 2ca2d41..92d0e67 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -332,6 +332,7 @@ typedef struct {
int ufd_uptodate;
int ufd_len;
struct pollfd *ufds;
+ int poll_running;
} pollObject;
static PyTypeObject poll_Type;
@@ -528,16 +529,27 @@ poll_poll(pollObject *self, PyObject *args)
return NULL;
}
+ /* Avoid concurrent poll() invocation, issue 8865 */
+ if (self->poll_running) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "concurrent poll() invocation");
+ return NULL;
+ }
+
/* Ensure the ufd array is up to date */
if (!self->ufd_uptodate)
if (update_ufd_array(self) == 0)
return NULL;
+ self->poll_running = 1;
+
/* call poll() */
Py_BEGIN_ALLOW_THREADS
poll_result = poll(self->ufds, self->ufd_len, timeout);
Py_END_ALLOW_THREADS
+ self->poll_running = 0;
+
if (poll_result < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
@@ -614,6 +626,7 @@ newPollObject(void)
array pointed to by ufds matches the contents of the dictionary. */
self->ufd_uptodate = 0;
self->ufds = NULL;
+ self->poll_running = 0;
self->dict = PyDict_New();
if (self->dict == NULL) {
Py_DECREF(self);