Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c4e6e0a2
Commit
c4e6e0a2
authored
Apr 02, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bail in unicode error's __str__ methods if the objects are not properly initialized (closes #21134)
parent
9190b6f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
0 deletions
+21
-0
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+6
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/exceptions.c
Objects/exceptions.c
+12
-0
No files found.
Lib/test/test_exceptions.py
View file @
c4e6e0a2
...
...
@@ -431,6 +431,12 @@ class ExceptionTests(unittest.TestCase):
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
)),
""
)
def
test_badisinstance
(
self
):
# Bug #2542: if issubclass(e, MyException) raises an exception,
# it should be ignored
...
...
Misc/NEWS
View file @
c4e6e0a2
...
...
@@ -12,6 +12,9 @@ Core and Builtins
- Issue #20437: Fixed 43 potential bugs when deleting objects references.
- Issue #21134: Fix segfault when str is called on an uninitialized
UnicodeEncodeError, UnicodeDecodeError, or UnicodeTranslateError object.
- Issue #20494: Ensure that free()d memory arenas are really released on POSIX
systems supporting anonymous memory mappings. Patch by Charles-François
Natali.
...
...
Objects/exceptions.c
View file @
c4e6e0a2
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment