Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4705,10 +4705,10 @@ def testSetBlocking_overflow(self):
self.skipTest('needs UINT_MAX < ULONG_MAX')

self.serv.setblocking(False)
self.assertEqual(self.serv.gettimeout(), 0.0)
self.assert_sock_timeout(self.serv, 0.0)

self.serv.setblocking(_testcapi.UINT_MAX + 1)
self.assertIsNone(self.serv.gettimeout())
self.assert_sock_timeout(self.serv, None)

_testSetBlocking_overflow = support.cpython_only(_testSetBlocking)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix unexpected integer truncation in :meth:`socket.setblocking` which caused
it to interpret multiples of ``2**32`` as ``False``.
8 changes: 5 additions & 3 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2815,12 +2815,14 @@ For IP sockets, the address info is a pair (hostaddr, port).");
static PyObject *
sock_setblocking(PySocketSockObject *s, PyObject *arg)
{
long block;
long value;
int block;

block = PyLong_AsLong(arg);
if (block == -1 && PyErr_Occurred())
value = PyLong_AsLong(arg);
if (value == -1 && PyErr_Occurred())
return NULL;

block = (value != 0);
s->sock_timeout = _PyTime_FromSeconds(block ? -1 : 0);
if (internal_setblocking(s, block) == -1) {
return NULL;
Expand Down