--- Python-2.3.3/Modules/fcntlmodule.c.orig 2006-02-20 11:11:03.000000000 -0600 +++ Python-2.3.3/Modules/fcntlmodule.c 2006-02-20 11:15:13.000000000 -0600 @@ -93,6 +93,7 @@ static PyObject * fcntl_ioctl(PyObject *self, PyObject *args) { +#define IOCTL_BUFSZ 1024 int fd; int code; int arg; @@ -100,7 +101,7 @@ char *str; int len; int mutate_arg = 0; - char buf[1024]; + char buf[IOCTL_BUFSZ+1]; /* +1 for adding a null byte to strings for C */ if (PyArg_ParseTuple(args, "O&iw#|i:ioctl", conv_descriptor, &fd, &code, @@ -112,7 +113,7 @@ mutate_arg = 0; } if (mutate_arg) { - if (len <= sizeof buf) { + if (len <= IOCTL_BUFSZ) { memcpy(buf, str, len); arg = buf; } @@ -121,7 +122,7 @@ } } else { - if (len > sizeof buf) { + if (len > IOCTL_BUFSZ) { PyErr_SetString(PyExc_ValueError, "ioctl string arg too long"); return NULL; @@ -139,7 +140,7 @@ 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) { @@ -157,12 +158,13 @@ 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