summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-12-16 11:28:32 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-12-16 11:28:32 (GMT)
commitc345ce1a69b3c4a46d87ef56d859bc70abfc74b4 (patch)
tree5481a8c3e31ae8a423aed9199a1fe2b22694d1c0 /Modules/_io
parent87448819abd4900bcb36857c6706d8562c97a099 (diff)
downloadcpython-c345ce1a69b3c4a46d87ef56d859bc70abfc74b4.zip
cpython-c345ce1a69b3c4a46d87ef56d859bc70abfc74b4.tar.gz
cpython-c345ce1a69b3c4a46d87ef56d859bc70abfc74b4.tar.bz2
Issue #10350: Read and save errno before calling a function which might overwrite it.
Original patch by Hallvard B Furuseth.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/fileio.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index be5c9f8..f39f8b0 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -506,6 +506,7 @@ fileio_readinto(fileio *self, PyObject *args)
{
Py_buffer pbuf;
Py_ssize_t n, len;
+ int err;
if (self->fd < 0)
return err_closed();
@@ -529,10 +530,12 @@ fileio_readinto(fileio *self, PyObject *args)
Py_END_ALLOW_THREADS
} else
n = -1;
+ err = errno;
PyBuffer_Release(&pbuf);
if (n < 0) {
- if (errno == EAGAIN)
+ if (err == EAGAIN)
Py_RETURN_NONE;
+ errno = err;
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -675,9 +678,11 @@ fileio_read(fileio *self, PyObject *args)
n = -1;
if (n < 0) {
+ int err = errno;
Py_DECREF(bytes);
- if (errno == EAGAIN)
+ if (err == EAGAIN)
Py_RETURN_NONE;
+ errno = err;
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
@@ -697,6 +702,7 @@ fileio_write(fileio *self, PyObject *args)
{
Py_buffer pbuf;
Py_ssize_t n, len;
+ int err;
if (self->fd < 0)
return err_closed();
@@ -727,12 +733,14 @@ fileio_write(fileio *self, PyObject *args)
Py_END_ALLOW_THREADS
} else
n = -1;
+ err = errno;
PyBuffer_Release(&pbuf);
if (n < 0) {
- if (errno == EAGAIN)
+ if (err == EAGAIN)
Py_RETURN_NONE;
+ errno = err;
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}