Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6214edd

Browse files
committed
merge r68768 to py3k
1 parent 7aedf11 commit 6214edd

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

Lib/test/test_multiprocessing.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def latin(s):
6262
HAVE_GETVALUE = not getattr(_multiprocessing,
6363
'HAVE_BROKEN_SEM_GETVALUE', False)
6464

65+
WIN32 = (sys.platform == "win32")
66+
6567
#
6668
# Creates a wrapper for a function which records the time it takes to finish
6769
#
@@ -1683,6 +1685,18 @@ def test_level(self):
16831685
logger.setLevel(level=LOG_LEVEL)
16841686

16851687
#
1688+
# Test to verify handle verification, see issue 3321
1689+
#
1690+
1691+
class TestInvalidHandle(unittest.TestCase):
1692+
1693+
def test_invalid_handles(self):
1694+
if WIN32:
1695+
return
1696+
conn = _multiprocessing.Connection(44977608)
1697+
self.assertRaises(IOError, conn.poll)
1698+
self.assertRaises(IOError, _multiprocessing.Connection, -1)
1699+
#
16861700
# Functions used to create test cases from the base ones in this module
16871701
#
16881702

@@ -1786,7 +1800,7 @@ def send_bytes(self, data):
17861800
multiprocessing.connection.answer_challenge,
17871801
_FakeConnection(), b'abc')
17881802

1789-
testcases_other = [OtherTest]
1803+
testcases_other = [OtherTest, TestInvalidHandle]
17901804

17911805
#
17921806
#

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Library
143143
- Issue #4959: inspect.formatargspec now works for keyword only arguments
144144
without defaults.
145145

146+
- Issue #3321: _multiprocessing.Connection() doesn't check handle; added checks
147+
for *nix machines for negative handles and large int handles. Without this check
148+
it is possible to segfault the interpreter.
149+
146150
- Issue #4449: AssertionError in mp_benchmarks.py, caused by an underlying issue
147151
in sharedctypes.py.
148152

Modules/_multiprocessing/connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ connection_poll(ConnectionObject *self, PyObject *args)
362362
}
363363

364364
Py_BEGIN_ALLOW_THREADS
365-
res = conn_poll(self, timeout);
365+
res = conn_poll(self, timeout, _save);
366366
Py_END_ALLOW_THREADS
367367

368368
switch (res) {

Modules/_multiprocessing/socket_connection.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,23 @@ conn_recv_string(ConnectionObject *conn, char *buffer,
153153
*/
154154

155155
static int
156-
conn_poll(ConnectionObject *conn, double timeout)
156+
conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
157157
{
158158
int res;
159159
fd_set rfds;
160160

161+
/*
162+
* Verify the handle, issue 3321. Not required for windows.
163+
*/
164+
#ifndef MS_WINDOWS
165+
if (((int)conn->handle) < 0 || ((int)conn->handle) >= FD_SETSIZE) {
166+
Py_BLOCK_THREADS
167+
PyErr_SetString(PyExc_IOError, "handle out of range in select()");
168+
Py_UNBLOCK_THREADS
169+
return MP_EXCEPTION_HAS_BEEN_SET;
170+
}
171+
#endif
172+
161173
FD_ZERO(&rfds);
162174
FD_SET((SOCKET)conn->handle, &rfds);
163175

0 commit comments

Comments
 (0)