diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_cursesmodule.c | 1 | ||||
-rw-r--r-- | Modules/_elementtree.c | 2 | ||||
-rw-r--r-- | Modules/_io/_iomodule.c | 2 | ||||
-rw-r--r-- | Modules/_io/bytesio.c | 24 | ||||
-rw-r--r-- | Modules/_io/iobase.c | 2 | ||||
-rw-r--r-- | Modules/_io/stringio.c | 19 | ||||
-rw-r--r-- | Modules/_io/textio.c | 2 | ||||
-rw-r--r-- | Modules/_ssl.c | 2 | ||||
-rw-r--r-- | Modules/_testbuffer.c | 5 | ||||
-rw-r--r-- | Modules/mmapmodule.c | 11 | ||||
-rw-r--r-- | Modules/posixmodule.c | 9 | ||||
-rw-r--r-- | Modules/selectmodule.c | 2 | ||||
-rw-r--r-- | Modules/socketmodule.c | 3 | ||||
-rw-r--r-- | Modules/zipimport.c | 8 |
14 files changed, 70 insertions, 22 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 3f9ca13..4e1449b 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -1938,6 +1938,7 @@ PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value) if (ascii == NULL) return -1; encoding = strdup(PyBytes_AS_STRING(ascii)); + Py_DECREF(ascii); if (encoding == NULL) { PyErr_NoMemory(); return -1; diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 6f17d80..43f9d9b 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -98,7 +98,7 @@ do { memory -= size; printf("%8d - %s\n", memory, comment); } while (0) info. */ #define JOIN_GET(p) ((Py_uintptr_t) (p) & 1) #define JOIN_SET(p, flag) ((void*) ((Py_uintptr_t) (JOIN_OBJ(p)) | (flag))) -#define JOIN_OBJ(p) ((PyObject*) ((Py_uintptr_t) (p) & ~1)) +#define JOIN_OBJ(p) ((PyObject*) ((Py_uintptr_t) (p) & ~(Py_uintptr_t)1)) /* glue functions (see the init function for details) */ static PyObject* elementtree_parseerror_obj; diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 0622c58..d3a87e7 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -185,7 +185,7 @@ PyDoc_STRVAR(open_doc, "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" -" newline is '' or '\n', no translation takes place. If newline is any\n" +" newline is '' or '\\n', no translation takes place. If newline is any\n" " of the other legal values, any '\\n' characters written are translated\n" " to the given string.\n" "\n" diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index 3d027e2..54840bb 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -121,7 +121,7 @@ resize_buffer(bytesio *self, size_t size) } /* Internal routine for writing a string of bytes to the buffer of a BytesIO - object. Returns the number of bytes wrote, or -1 on error. */ + object. Returns the number of bytes written, or -1 on error. */ static Py_ssize_t write_bytes(bytesio *self, const char *bytes, Py_ssize_t len) { @@ -171,10 +171,20 @@ bytesio_get_closed(bytesio *self) } } +PyDoc_STRVAR(readable_doc, +"readable() -> bool. Returns True if the IO object can be read."); + +PyDoc_STRVAR(writable_doc, +"writable() -> bool. Returns True if the IO object can be written."); + +PyDoc_STRVAR(seekable_doc, +"seekable() -> bool. Returns True if the IO object can be seeked."); + /* Generic getter for the writable, readable and seekable properties */ static PyObject * -return_true(bytesio *self) +return_not_closed(bytesio *self) { + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -682,8 +692,10 @@ bytesio_getstate(bytesio *self) } else { dict = PyDict_Copy(self->dict); - if (dict == NULL) + if (dict == NULL) { + Py_DECREF(initvalue); return NULL; + } } state = Py_BuildValue("(OnN)", initvalue, self->pos, dict); @@ -867,9 +879,9 @@ static PyGetSetDef bytesio_getsetlist[] = { }; static struct PyMethodDef bytesio_methods[] = { - {"readable", (PyCFunction)return_true, METH_NOARGS, NULL}, - {"seekable", (PyCFunction)return_true, METH_NOARGS, NULL}, - {"writable", (PyCFunction)return_true, METH_NOARGS, NULL}, + {"readable", (PyCFunction)return_not_closed, METH_NOARGS, readable_doc}, + {"seekable", (PyCFunction)return_not_closed, METH_NOARGS, seekable_doc}, + {"writable", (PyCFunction)return_not_closed, METH_NOARGS, writable_doc}, {"close", (PyCFunction)bytesio_close, METH_NOARGS, close_doc}, {"flush", (PyCFunction)bytesio_flush, METH_NOARGS, flush_doc}, {"isatty", (PyCFunction)bytesio_isatty, METH_NOARGS, isatty_doc}, diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index dd052ae..babb019 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -442,7 +442,7 @@ PyDoc_STRVAR(iobase_readline_doc, "\n" "If limit is specified, at most limit bytes will be read.\n" "\n" - "The line terminator is always b'\n' for binary files; for text\n" + "The line terminator is always b'\\n' for binary files; for text\n" "files, the newlines argument to open can be used to select the line\n" "terminator(s) recognized.\n"); diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index a1c31c0..9d73884 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -760,10 +760,21 @@ stringio_init(stringio *self, PyObject *args, PyObject *kwds) } /* Properties and pseudo-properties */ + +PyDoc_STRVAR(stringio_readable_doc, +"readable() -> bool. Returns True if the IO object can be read."); + +PyDoc_STRVAR(stringio_writable_doc, +"writable() -> bool. Returns True if the IO object can be written."); + +PyDoc_STRVAR(stringio_seekable_doc, +"seekable() -> bool. Returns True if the IO object can be seeked."); + static PyObject * stringio_seekable(stringio *self, PyObject *args) { CHECK_INITIALIZED(self); + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -771,6 +782,7 @@ static PyObject * stringio_readable(stringio *self, PyObject *args) { CHECK_INITIALIZED(self); + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -778,6 +790,7 @@ static PyObject * stringio_writable(stringio *self, PyObject *args) { CHECK_INITIALIZED(self); + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -956,9 +969,9 @@ static struct PyMethodDef stringio_methods[] = { {"seek", (PyCFunction)stringio_seek, METH_VARARGS, stringio_seek_doc}, {"write", (PyCFunction)stringio_write, METH_O, stringio_write_doc}, - {"seekable", (PyCFunction)stringio_seekable, METH_NOARGS}, - {"readable", (PyCFunction)stringio_readable, METH_NOARGS}, - {"writable", (PyCFunction)stringio_writable, METH_NOARGS}, + {"seekable", (PyCFunction)stringio_seekable, METH_NOARGS, stringio_seekable_doc}, + {"readable", (PyCFunction)stringio_readable, METH_NOARGS, stringio_readable_doc}, + {"writable", (PyCFunction)stringio_writable, METH_NOARGS, stringio_writable_doc}, {"__getstate__", (PyCFunction)stringio_getstate, METH_NOARGS}, {"__setstate__", (PyCFunction)stringio_setstate, METH_O}, diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index fb9b674..96434a8 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -648,7 +648,7 @@ PyDoc_STRVAR(textiowrapper_doc, "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" - " newline is '' or '\n', no translation takes place. If newline is any\n" + " newline is '' or '\\n', no translation takes place. If newline is any\n" " of the other legal values, any '\\n' characters written are translated\n" " to the given string.\n" "\n" diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 1516b87..ad22c52 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -2488,7 +2488,7 @@ PySSL_RAND_egd(PyObject *self, PyObject *args) PyObject *path; int bytes; - if (!PyArg_ParseTuple(args, "O&|i:RAND_egd", + if (!PyArg_ParseTuple(args, "O&:RAND_egd", PyUnicode_FSConverter, &path)) return NULL; diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c index 87ada0a..316666e 100644 --- a/Modules/_testbuffer.c +++ b/Modules/_testbuffer.c @@ -16,6 +16,7 @@ PyObject *calcsize = NULL; static const char *simple_fmt = "B"; PyObject *simple_format = NULL; #define SIMPLE_FORMAT(fmt) (fmt == NULL || strcmp(fmt, "B") == 0) +#define FIX_FORMAT(fmt) (fmt == NULL ? "B" : fmt) /**************************************************************************/ @@ -513,10 +514,8 @@ static int cmp_structure(Py_buffer *dest, Py_buffer *src) { Py_ssize_t i; - int same_fmt = ((dest->format == NULL && src->format == NULL) || \ - (strcmp(dest->format, src->format) == 0)); - if (!same_fmt || + if (strcmp(FIX_FORMAT(dest->format), FIX_FORMAT(src->format)) != 0 || dest->itemsize != src->itemsize || dest->ndim != src->ndim) return -1; diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index f52dce5..d650eae 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1163,6 +1163,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { if (map_size == 0) { off_t calc_size; + if (st.st_size == 0) { + PyErr_SetString(PyExc_ValueError, + "cannot mmap an empty file"); + return NULL; + } if (offset >= st.st_size) { PyErr_SetString(PyExc_ValueError, "mmap offset is greater than file size"); @@ -1359,6 +1364,12 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) } size = (((PY_LONG_LONG) high) << 32) + low; + if (size == 0) { + PyErr_SetString(PyExc_ValueError, + "cannot mmap an empty file"); + Py_DECREF(m_obj); + return NULL; + } if (offset >= size) { PyErr_SetString(PyExc_ValueError, "mmap offset is greater than file size"); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 55aeb61..bd94ffb 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -414,7 +414,14 @@ win32_warn_bytes_api() #ifdef AT_FDCWD -#define DEFAULT_DIR_FD AT_FDCWD +/* + * Why the (int) cast? Solaris 10 defines AT_FDCWD as 0xffd19553 (-3041965); + * without the int cast, the value gets interpreted as uint (4291925331), + * which doesn't play nicely with all the initializer lines in this file that + * look like this: + * int dir_fd = DEFAULT_DIR_FD; + */ +#define DEFAULT_DIR_FD (int)AT_FDCWD #else #define DEFAULT_DIR_FD (-100) #endif diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 5b5eb92..7cec49b 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -239,7 +239,7 @@ select_select(PyObject *self, PyObject *args) #else /* 64-bit OS X has struct timeval.tv_usec as an int (and thus still 4 bytes as required), but no longer defined by a long. */ - long tv_usec = tv.tv_usec; + long tv_usec; if (_PyTime_ObjectToTimeval(tout, &tv.tv_sec, &tv_usec) == -1) return NULL; tv.tv_usec = tv_usec; diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 7176674..d8c81fe 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1674,7 +1674,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, if (len == 0) { ifr.ifr_ifindex = 0; } else if (len < sizeof(ifr.ifr_name)) { - strcpy(ifr.ifr_name, PyBytes_AS_STRING(interfaceName)); + strncpy(ifr.ifr_name, PyBytes_AS_STRING(interfaceName), sizeof(ifr.ifr_name)); + ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0'; if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { s->errorhandler(); Py_DECREF(interfaceName); diff --git a/Modules/zipimport.c b/Modules/zipimport.c index 12bfe23..ccbc784 100644 --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -236,12 +236,16 @@ make_filename(PyObject *prefix, PyObject *name) return NULL; } - if (!PyUnicode_AsUCS4(prefix, p, len, 0)) + if (!PyUnicode_AsUCS4(prefix, p, len, 0)) { + PyMem_Free(buf); return NULL; + } p += PyUnicode_GET_LENGTH(prefix); len -= PyUnicode_GET_LENGTH(prefix); - if (!PyUnicode_AsUCS4(name, p, len, 1)) + if (!PyUnicode_AsUCS4(name, p, len, 1)) { + PyMem_Free(buf); return NULL; + } for (; *p; p++) { if (*p == '.') *p = SEP; |