diff options
author | Yury Selivanov <yury@magic.io> | 2016-10-06 18:03:03 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-10-06 18:03:03 (GMT) |
commit | cb9424f6435cf02ba913d0263d69524bcc294095 (patch) | |
tree | 2aa10f72bab55e98814228a9b77e0e824abdc85d /Lib/test | |
parent | 26d998cfdd1f843a154e5398d09c0270fa17aa30 (diff) | |
download | cpython-cb9424f6435cf02ba913d0263d69524bcc294095.zip cpython-cb9424f6435cf02ba913d0263d69524bcc294095.tar.gz cpython-cb9424f6435cf02ba913d0263d69524bcc294095.tar.bz2 |
Issue #27759: Fix selectors incorrectly retain invalid file descriptors.
(Backported to 3.4 as this bug might be exploited to for DoS)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_selectors.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py index 952fda6..28cd948 100644 --- a/Lib/test/test_selectors.py +++ b/Lib/test/test_selectors.py @@ -5,6 +5,7 @@ import selectors import signal import socket import sys +import tempfile from test import support from time import sleep import unittest @@ -447,6 +448,16 @@ class EpollSelectorTestCase(BaseSelectorTestCase, ScalableSelectorMixIn): SELECTOR = getattr(selectors, 'EpollSelector', None) + def test_register_file(self): + # epoll(7) returns EPERM when given a file to watch + s = self.SELECTOR() + with tempfile.NamedTemporaryFile() as f: + with self.assertRaises(IOError): + s.register(f, selectors.EVENT_READ) + # the SelectorKey has been removed + with self.assertRaises(KeyError): + s.get_key(f) + @unittest.skipUnless(hasattr(selectors, 'KqueueSelector'), "Test needs selectors.KqueueSelector)") @@ -454,6 +465,18 @@ class KqueueSelectorTestCase(BaseSelectorTestCase, ScalableSelectorMixIn): SELECTOR = getattr(selectors, 'KqueueSelector', None) + def test_register_bad_fd(self): + # a file descriptor that's been closed should raise an OSError + # with EBADF + s = self.SELECTOR() + bad_f = support.make_bad_fd() + with self.assertRaises(OSError) as cm: + s.register(bad_f, selectors.EVENT_READ) + self.assertEqual(cm.exception.errno, errno.EBADF) + # the SelectorKey has been removed + with self.assertRaises(KeyError): + s.get_key(bad_f) + def test_main(): tests = [DefaultSelectorTestCase, SelectSelectorTestCase, |