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)
commitc4e6e0a27944893103f78090eb7d026be0f3707d (patch)
tree4db4778856a84f11c162001c4de7617345b8368f /Objects/exceptions.c
parent9190b6f4a6f4119d6459d04a74f9b1ad511d1ca0 (diff)
downloadcpython-c4e6e0a27944893103f78090eb7d026be0f3707d.zip
cpython-c4e6e0a27944893103f78090eb7d026be0f3707d.tar.gz
cpython-c4e6e0a27944893103f78090eb7d026be0f3707d.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 0f86cfb..e165528 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1648,6 +1648,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);
@@ -1733,6 +1737,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);
@@ -1830,6 +1838,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);