changeset: 90112:0aeaea247d7d parent: 90109:2c21a901717a parent: 90110:140c5da3dc82 user: Benjamin Peterson date: Wed Apr 02 12:16:55 2014 -0400 files: Misc/NEWS description: merge 3.4 (#21134) diff -r 2c21a901717a -r 0aeaea247d7d Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Wed Apr 02 12:05:41 2014 -0400 +++ b/Lib/test/test_exceptions.py Wed Apr 02 12:16:55 2014 -0400 @@ -800,6 +800,12 @@ u.start = 1000 self.assertEqual(str(u), "can't translate characters in position 1000-4: 965230951443685724997") + def test_unicode_errors_no_object(self): + # See issue #21134. + klasses = UnicodeDecodeError, UnicodeDecodeError, UnicodeTranslateError + for klass in klasses: + self.assertEqual(str(klass.__new__(klass)), "") + @no_tracing def test_badisinstance(self): # Bug #2542: if issubclass(e, MyException) raises an exception, diff -r 2c21a901717a -r 0aeaea247d7d Misc/NEWS --- a/Misc/NEWS Wed Apr 02 12:05:41 2014 -0400 +++ b/Misc/NEWS Wed Apr 02 12:16:55 2014 -0400 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #21134: Fix segfault when str is called on an uninitialized + UnicodeEncodeError, UnicodeDecodeError, or UnicodeTranslateError object. + - Issue #19537: Fix PyUnicode_DATA() alignment under m68k. Patch by Andreas Schwab. diff -r 2c21a901717a -r 0aeaea247d7d Objects/exceptions.c --- a/Objects/exceptions.c Wed Apr 02 12:05:41 2014 -0400 +++ b/Objects/exceptions.c Wed Apr 02 12:16:55 2014 -0400 @@ -1837,6 +1837,10 @@ 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 @@ 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 @@ 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);