summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-19 10:41:45 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-19 10:41:45 (GMT)
commit9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3 (patch)
treec61aebdba4dddc8f10c9460ca33b0fa3f2e1495d /Lib/test/test_socket.py
parentbd8f29028eab752e8e5c73703218a701028c1a9a (diff)
parent441d30fac7f4037e4a79e4ada873de3b6f6e5a26 (diff)
downloadcpython-9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3.zip
cpython-9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3.tar.gz
cpython-9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3.tar.bz2
Issue #15989: Fix several occurrences of integer overflow
when result of PyLong_AsLong() narrowed to int without checks. This is a backport of changesets 13e2e44db99d and 525407d89277.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 5a19051..da6ef05 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1262,11 +1262,17 @@ class GeneralModuleTests(unittest.TestCase):
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
self.assertRaises(TypeError, pickle.dumps, sock, protocol)
- def test_listen_backlog0(self):
+ def test_listen_backlog(self):
+ for backlog in 0, -1:
+ srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ srv.bind((HOST, 0))
+ srv.listen(backlog)
+ srv.close()
+
+ # Issue 15989
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.bind((HOST, 0))
- # backlog = 0
- srv.listen(0)
+ self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1)
srv.close()
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
@@ -1582,6 +1588,11 @@ class BasicTCPTest(SocketConnectedTest):
def _testShutdown(self):
self.serv_conn.send(MSG)
+ # Issue 15989
+ self.assertRaises(OverflowError, self.serv_conn.shutdown,
+ _testcapi.INT_MAX + 1)
+ self.assertRaises(OverflowError, self.serv_conn.shutdown,
+ 2 + (_testcapi.UINT_MAX + 1))
self.serv_conn.shutdown(2)
def testDetach(self):
@@ -3555,7 +3566,10 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
def testSetBlocking(self):
# Testing whether set blocking works
- self.serv.setblocking(0)
+ self.serv.setblocking(True)
+ self.assertIsNone(self.serv.gettimeout())
+ self.serv.setblocking(False)
+ self.assertEqual(self.serv.gettimeout(), 0.0)
start = time.time()
try:
self.serv.accept()
@@ -3563,6 +3577,10 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
pass
end = time.time()
self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.")
+ # Issue 15989
+ if _testcapi.UINT_MAX < _testcapi.ULONG_MAX:
+ self.serv.setblocking(_testcapi.UINT_MAX + 1)
+ self.assertIsNone(self.serv.gettimeout())
def _testSetBlocking(self):
pass