From: Matthias Klose Date: Wed, 26 Nov 2008 17:22:04 +0000 (+0000) Subject: - Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2. X-Git-Tag: v3.0~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e1b8faacc60fcd201b20a88e768c5ece2ee27f3;p=python - Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2. --- diff --git a/Misc/NEWS b/Misc/NEWS index 091ef43eb0..6145654c06 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,8 @@ Core and Builtins - Issue #4367: Python would segfault during compiling when the unicodedata module couldn't be imported and \N escapes were present. +- Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2. + Library ------- diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 4f99da5af0..3764f482af 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -1857,6 +1857,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) int fd; FILE *fp; PyObject *data; + size_t datalen; WINDOW *win; PyCursesInitialised @@ -1886,7 +1887,13 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) remove(fn); return NULL; } - fwrite(PyBytes_AS_STRING(data), 1, PyBytes_GET_SIZE(data), fp); + datalen = PyBytes_GET_SIZE(data); + if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) { + Py_DECREF(data); + fclose(fp); + remove(fn); + return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); + } Py_DECREF(data); fseek(fp, 0, 0); win = getwin(fp);