From 131a6414dd023d8bfa71a05e76030c1e0aaf2c1d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 9 Apr 2011 23:49:58 +0200 Subject: =?UTF-8?q?Issue=20#11757:=20select.select()=20now=20raises=20Valu?= =?UTF-8?q?eError=20when=20a=20negative=20timeout=20is=20passed=20(previou?= =?UTF-8?q?sly,=20a=20select.error=20with=20EINVAL=20would=20be=20raised).?= =?UTF-8?q?=20=20Patch=20by=20Charles-Fran=C3=A7ois=20Natali.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/test/test_select.py | 1 + Misc/NEWS | 4 ++++ Modules/selectmodule.c | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/Lib/test/test_select.py b/Lib/test/test_select.py index fe92f45..4a13ade 100644 --- a/Lib/test/test_select.py +++ b/Lib/test/test_select.py @@ -20,6 +20,7 @@ class SelectTestCase(unittest.TestCase): self.assertRaises(TypeError, select.select, [self.Nope()], [], []) self.assertRaises(TypeError, select.select, [self.Almost()], [], []) self.assertRaises(TypeError, select.select, [], [], [], "not a number") + self.assertRaises(ValueError, select.select, [], [], [], -1) def test_returned_list_identity(self): # See issue #8329 diff --git a/Misc/NEWS b/Misc/NEWS index 2b43122..95e5446 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -103,6 +103,10 @@ Core and Builtins Library ------- +- Issue #11757: select.select() now raises ValueError when a negative timeout + is passed (previously, a select.error with EINVAL would be raised). Patch + by Charles-François Natali. + - Issue #7311: fix html.parser to accept non-ASCII attribute values. - Issue #11605: email.parser.BytesFeedParser was incorrectly converting multipart diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 65e1826..5aa67dd 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -234,6 +234,11 @@ select_select(PyObject *self, PyObject *args) "timeout period too long"); return NULL; } + if (timeout < 0) { + PyErr_SetString(PyExc_ValueError, + "timeout must be non-negative"); + return NULL; + } seconds = (long)timeout; timeout = timeout - (double)seconds; tv.tv_sec = seconds; -- cgit v0.12