]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merge 68778,68788 to maint
authorJesse Noller <jnoller@gmail.com>
Thu, 12 Feb 2009 19:44:58 +0000 (19:44 +0000)
committerJesse Noller <jnoller@gmail.com>
Thu, 12 Feb 2009 19:44:58 +0000 (19:44 +0000)
Lib/test/test_multiprocessing.py
Misc/NEWS
Modules/_multiprocessing/connection.h
Modules/_multiprocessing/pipe_connection.c
Modules/_multiprocessing/socket_connection.c

index 4e5d7597cbe3255b22f6ae04abc86eec39914b2b..9a307dee7ac0a3cca63658243782a3721c65c907 100644 (file)
@@ -62,6 +62,8 @@ else:
 HAVE_GETVALUE = not getattr(_multiprocessing,
                             'HAVE_BROKEN_SEM_GETVALUE', False)
 
+WIN32 = (sys.platform == "win32")
+
 #
 # Creates a wrapper for a function which records the time it takes to finish
 #
@@ -1683,6 +1685,18 @@ class _TestLogging(BaseTestCase):
         logger.setLevel(level=LOG_LEVEL)
 
 #
+# Test to verify handle verification, see issue 3321
+#
+
+class TestInvalidHandle(unittest.TestCase):
+
+    def test_invalid_handles(self):
+        if WIN32:
+            return
+        conn = _multiprocessing.Connection(44977608)
+        self.assertRaises(IOError, conn.poll)
+        self.assertRaises(IOError, _multiprocessing.Connection, -1)
+#
 # Functions used to create test cases from the base ones in this module
 #
 
@@ -1786,7 +1800,7 @@ class OtherTest(unittest.TestCase):
                           multiprocessing.connection.answer_challenge,
                           _FakeConnection(), b'abc')
 
-testcases_other = [OtherTest]
+testcases_other = [OtherTest, TestInvalidHandle]
 
 #
 #
index 8e3570a1e51edeecd55086b381b66d319e68265b..73779bfea689b7399d27afe2071d9f14a4d7c974 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -129,6 +129,13 @@ Library
 - Issue #3386: distutils.sysconfig.get_python_lib prefix argument was ignored
   under NT and OS2. Patch by Philip Jenvey.
 
+- Issue #3321: _multiprocessing.Connection() doesn't check handle; added checks
+  for *nix machines for negative handles and large int handles. Without this check
+  it is possible to segfault the interpreter.
+
+- Issue #4449: AssertionError in mp_benchmarks.py, caused by an underlying issue
+  in sharedctypes.py.
+
 - Issue #4890: Handle empty text search pattern in Tkinter.Text.search.
 
 - Partial fix to issue #1731706: memory leak in Tkapp_Call when calling
index c1e926af7a64d9da739d4f1af6b112cb3d652e19..581beacf9f6aa6bf242012e43dbb9913911f569f 100644 (file)
@@ -362,7 +362,7 @@ connection_poll(ConnectionObject *self, PyObject *args)
        }
 
        Py_BEGIN_ALLOW_THREADS
-       res = conn_poll(self, timeout);
+       res = conn_poll(self, timeout, _save);
        Py_END_ALLOW_THREADS
 
        switch (res) {
index ad16fc89d31ec30a2f269656790de158d209b676..27e79dda7d4a11823e8f56b93970f0a15cf9738c 100644 (file)
@@ -83,10 +83,8 @@ conn_recv_string(ConnectionObject *conn, char *buffer,
  * Check whether any data is available for reading
  */
 
-#define conn_poll(conn, timeout) conn_poll_save(conn, timeout, _save)
-
 static int
-conn_poll_save(ConnectionObject *conn, double timeout, PyThreadState *_save)
+conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
 {
        DWORD bytes, deadline, delay;
        int difference, res;
index e5d2d155d9fed6585ff984dcc618d2b0da67d935..ad4005b2e809f87836956b6a17574e7da3ee06be 100644 (file)
@@ -153,11 +153,23 @@ conn_recv_string(ConnectionObject *conn, char *buffer,
  */
 
 static int
-conn_poll(ConnectionObject *conn, double timeout)
+conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
 {
        int res;
        fd_set rfds;
 
+       /*
+        * Verify the handle, issue 3321. Not required for windows.
+        */ 
+       #ifndef MS_WINDOWS
+               if (((int)conn->handle) < 0 || ((int)conn->handle) >= FD_SETSIZE) {
+                       Py_BLOCK_THREADS
+                       PyErr_SetString(PyExc_IOError, "handle out of range in select()");
+                       Py_UNBLOCK_THREADS
+                       return MP_EXCEPTION_HAS_BEEN_SET;
+               }
+       #endif
+
        FD_ZERO(&rfds);
        FD_SET((SOCKET)conn->handle, &rfds);