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
1cb2e042
Commit
1cb2e042
authored
Mar 04, 2012
by
Armin Rigo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a crasher for the documented issue of calling "Py_DECREF(self->xxx)";
parent
21ccb731
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
Lib/test/crashers/decref_before_assignment.py
Lib/test/crashers/decref_before_assignment.py
+44
-0
No files found.
Lib/test/crashers/decref_before_assignment.py
0 → 100644
View file @
1cb2e042
"""
General example for an attack against code like this:
Py_DECREF(obj->attr); obj->attr = ...;
here in Module/_json.c:scanner_init().
Explanation: if the first Py_DECREF() calls either a __del__ or a
weakref callback, it will run while the 'obj' appears to have in
'obj->attr' still the old reference to the object, but not holding
the reference count any more.
Status: progress has been made replacing these cases, but there is an
infinite number of such cases.
"""
import
_json
,
weakref
class
Ctx1
(
object
):
encoding
=
"utf8"
strict
=
None
object_hook
=
None
object_pairs_hook
=
None
parse_float
=
None
parse_int
=
None
parse_constant
=
None
class
Foo
(
unicode
):
pass
def
delete_me
(
*
args
):
print
scanner
.
encoding
.
__dict__
class
Ctx2
(
Ctx1
):
@
property
def
encoding
(
self
):
global
wref
f
=
Foo
(
"utf8"
)
f
.
abc
=
globals
()
wref
=
weakref
.
ref
(
f
,
delete_me
)
return
f
scanner
=
_json
.
make_scanner
(
Ctx1
())
scanner
.
__init__
(
Ctx2
())
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