summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-04-02 16:15:06 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-04-02 16:15:06 (GMT)
commit9b09ba1234f8ba7a01eaf8986147ae0758712089 (patch)
tree04928077ec795bc7fd41d0e5ab77532bb2092b08 /Objects/exceptions.c
parent24dfb05d4f7de2d28db2c69560d3afa8f612242c (diff)
downloadcpython-9b09ba1234f8ba7a01eaf8986147ae0758712089.zip
cpython-9b09ba1234f8ba7a01eaf8986147ae0758712089.tar.gz
cpython-9b09ba1234f8ba7a01eaf8986147ae0758712089.tar.bz2
bail in unicode error's __str__ methods if the objects are not properly initialized (closes #21134)
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 44e60dd..861dbc7 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1837,6 +1837,10 @@ UnicodeEncodeError_str(PyObject *self)
PyObject *reason_str = NULL;
PyObject *encoding_str = NULL;
+ if (!uself->object)
+ /* Not properly initialized. */
+ return PyUnicode_FromString("");
+
/* Get reason and encoding as strings, which they might not be if
they've been modified after we were contructed. */
reason_str = PyObject_Str(uself->reason);
@@ -1955,6 +1959,10 @@ UnicodeDecodeError_str(PyObject *self)
PyObject *reason_str = NULL;
PyObject *encoding_str = NULL;
+ if (!uself->object)
+ /* Not properly initialized. */
+ return PyUnicode_FromString("");
+
/* Get reason and encoding as strings, which they might not be if
they've been modified after we were contructed. */
reason_str = PyObject_Str(uself->reason);
@@ -2049,6 +2057,10 @@ UnicodeTranslateError_str(PyObject *self)
PyObject *result = NULL;
PyObject *reason_str = NULL;
+ if (!uself->object)
+ /* Not properly initialized. */
+ return PyUnicode_FromString("");
+
/* Get reason as a string, which it might not be if it's been
modified after we were contructed. */
reason_str = PyObject_Str(uself->reason);