summaryrefslogtreecommitdiffstats
path: root/Modules/_io/textio.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-19 17:25:29 (GMT)
committerGitHub <noreply@github.com>2017-03-19 17:25:29 (GMT)
commita5af6e1af77ee0f9294c5776478a9c24d9fbab94 (patch)
treef4c9791260db737fea9da4f415d9facad9c96ae1 /Modules/_io/textio.c
parent77ed11552da3e01dd235b7d68988076866b1f604 (diff)
downloadcpython-a5af6e1af77ee0f9294c5776478a9c24d9fbab94.zip
cpython-a5af6e1af77ee0f9294c5776478a9c24d9fbab94.tar.gz
cpython-a5af6e1af77ee0f9294c5776478a9c24d9fbab94.tar.bz2
bpo-25455: Fixed crashes in repr of recursive buffered file-like objects. (#514)
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r--Modules/_io/textio.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 4133bf3..fce662a 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -2483,6 +2483,7 @@ static PyObject *
textiowrapper_repr(textio *self)
{
PyObject *nameobj, *modeobj, *res, *s;
+ int status;
CHECK_INITIALIZED(self);
@@ -2490,6 +2491,15 @@ textiowrapper_repr(textio *self)
if (res == NULL)
return NULL;
+ status = Py_ReprEnter((PyObject *)self);
+ if (status != 0) {
+ if (status > 0) {
+ PyErr_Format(PyExc_RuntimeError,
+ "reentrant call inside %s.__repr__",
+ Py_TYPE(self)->tp_name);
+ }
+ goto error;
+ }
nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name);
if (nameobj == NULL) {
if (PyErr_ExceptionMatches(PyExc_Exception))
@@ -2504,7 +2514,7 @@ textiowrapper_repr(textio *self)
goto error;
PyUnicode_AppendAndDel(&res, s);
if (res == NULL)
- return NULL;
+ goto error;
}
modeobj = _PyObject_GetAttrId((PyObject *) self, &PyId_mode);
if (modeobj == NULL) {
@@ -2520,14 +2530,21 @@ textiowrapper_repr(textio *self)
goto error;
PyUnicode_AppendAndDel(&res, s);
if (res == NULL)
- return NULL;
+ goto error;
}
s = PyUnicode_FromFormat("%U encoding=%R>",
res, self->encoding);
Py_DECREF(res);
+ if (status == 0) {
+ Py_ReprLeave((PyObject *)self);
+ }
return s;
-error:
+
+ error:
Py_XDECREF(res);
+ if (status == 0) {
+ Py_ReprLeave((PyObject *)self);
+ }
return NULL;
}