]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport SF bug/patch #1433877: string parameter to ioctl not null terminated
authorThomas Wouters <thomas@python.org>
Fri, 5 May 2006 10:52:43 +0000 (10:52 +0000)
committerThomas Wouters <thomas@python.org>
Fri, 5 May 2006 10:52:43 +0000 (10:52 +0000)
The new char-array used in ioctl calls wasn't explicitly NUL-terminated;
quite probably the cause for the test_pty failures on Solaris that we
circumvented earlier.

Lib/test/test_pty.py
Misc/ACKS
Modules/fcntlmodule.c

index 99e01b67bb067b109dfe6d05d160cf36427b699e..7b1f460ff116b8d7f828b61057678cb630a8f844 100644 (file)
@@ -4,13 +4,6 @@ from test.test_support import verbose, TestFailed, TestSkipped
 TEST_STRING_1 = "I wish to buy a fish license.\n"
 TEST_STRING_2 = "For my pet fish, Eric.\n"
 
-# Solaris (at least 2.9 and 2.10) seem to have a fickle isatty(). The first
-# test below, testing the result of os.openpty() for tty-ness, sometimes
-# (but not always) fails. The second isatty test, in the sub-process, always
-# works. Allow that fickle first test to fail on these platforms, since it
-# doesn't actually affect functionality.
-fickle_isatty = ["sunos5"]
-
 if verbose:
     def debug(msg):
         print msg
@@ -54,7 +47,7 @@ def test_basic_pty():
         # " An optional feature could not be imported " ... ?
         raise TestSkipped, "Pseudo-terminals (seemingly) not functional."
 
-    if not os.isatty(slave_fd) and sys.platform not in fickle_isatty:
+    if not os.isatty(slave_fd):
         raise TestFailed, "slave_fd is not a tty"
 
     debug("Writing to slave_fd")
index 350c5eab872944c008f85c33e03c410928fcebcd..479d4094e65cb69d04c53dfc021f85a700c18920 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -33,6 +33,7 @@ Greg Ball
 Luigi Ballabio
 Michael J. Barber
 Chris Barker
+Quentin Barnes
 Cesar Eduardo Barros
 Des Barry
 Ulf Bartelt
index 43f1773032317a323181dfdf92ce450936b0291e..6fa42f8199823742b37676670ec9f7b723df135d 100644 (file)
@@ -93,6 +93,7 @@ corresponding to the return value of the fcntl call in the C code.");
 static PyObject *
 fcntl_ioctl(PyObject *self, PyObject *args)
 {
+#define IOCTL_BUFSZ 1024
        int fd;
        int code;
        int arg;
@@ -100,7 +101,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
        char *str;
        int len;
        int mutate_arg = 0;
-       char buf[1024];
+       char buf[IOCTL_BUFSZ+1];  /* argument plus NUL byte */
 
        if (PyArg_ParseTuple(args, "O&iw#|i:ioctl",
                              conv_descriptor, &fd, &code, 
@@ -118,8 +119,9 @@ fcntl_ioctl(PyObject *self, PyObject *args)
                        mutate_arg = 0;
                }
                if (mutate_arg) {
-                       if (len <= sizeof buf) {
+                       if (len <= IOCTL_BUFSZ) {
                                memcpy(buf, str, len);
+                               buf[len] = '\0';
                                arg = buf;
                        } 
                        else {
@@ -127,13 +129,14 @@ fcntl_ioctl(PyObject *self, PyObject *args)
                        }
                }
                else {
-                       if (len > sizeof buf) {
+                       if (len > IOCTL_BUFSZ) {
                                PyErr_SetString(PyExc_ValueError,
                                        "ioctl string arg too long");
                                return NULL;
                        }
                        else {
                                memcpy(buf, str, len);
+                               buf[len] = '\0';
                                arg = buf;
                        }
                }
@@ -145,7 +148,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
                else {
                        ret = ioctl(fd, code, arg);
                }
-               if (mutate_arg && (len < sizeof buf)) {
+               if (mutate_arg && (len < IOCTL_BUFSZ)) {
                        memcpy(str, buf, len);
                }
                if (ret < 0) {
@@ -163,12 +166,13 @@ fcntl_ioctl(PyObject *self, PyObject *args)
        PyErr_Clear();
        if (PyArg_ParseTuple(args, "O&is#:ioctl",
                              conv_descriptor, &fd, &code, &str, &len)) {
-               if (len > sizeof buf) {
+               if (len > IOCTL_BUFSZ) {
                        PyErr_SetString(PyExc_ValueError,
                                        "ioctl string arg too long");
                        return NULL;
                }
                memcpy(buf, str, len);
+               buf[len] = '\0';
                Py_BEGIN_ALLOW_THREADS
                ret = ioctl(fd, code, buf);
                Py_END_ALLOW_THREADS
@@ -199,6 +203,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
                return NULL;
        }
        return PyInt_FromLong((long)ret);
+#undef IOCTL_BUFSZ
 }
 
 PyDoc_STRVAR(ioctl_doc,