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
48c2ef8a
Commit
48c2ef8a
authored
Jan 23, 2008
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix two crashers.
parent
ebb4f937
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
44 deletions
+11
-44
Lib/test/crashers/borrowed_ref_3.py
Lib/test/crashers/borrowed_ref_3.py
+0
-14
Lib/test/crashers/borrowed_ref_4.py
Lib/test/crashers/borrowed_ref_4.py
+0
-28
Python/bltinmodule.c
Python/bltinmodule.c
+6
-1
Python/ceval.c
Python/ceval.c
+5
-1
No files found.
Lib/test/crashers/borrowed_ref_3.py
deleted
100644 → 0
View file @
ebb4f937
"""
PyDict_GetItem() returns a borrowed reference.
There are probably a number of places that are open to attacks
such as the following one, in bltinmodule.c:min_max().
"""
class
KeyFunc
(
object
):
def
__call__
(
self
,
n
):
del
d
[
'key'
]
return
1
d
=
{
'key'
:
KeyFunc
()}
min
(
range
(
10
),
**
d
)
Lib/test/crashers/borrowed_ref_4.py
deleted
100644 → 0
View file @
ebb4f937
"""
PyDict_GetItem() returns a borrowed reference.
This attack is against ceval.c:IMPORT_NAME, which calls an
object (__builtin__.__import__) without holding a reference to it.
"""
import
types
import
__builtin__
class
X
(
object
):
def
__getattr__
(
self
,
name
):
# this is called with name == '__bases__' by PyObject_IsInstance()
# during the unbound method call -- it frees the unbound method
# itself before it invokes its im_func.
del
__builtin__
.
__import__
return
()
pseudoclass
=
X
()
class
Y
(
object
):
def
__call__
(
self
,
*
args
):
# 'self' was freed already
print
self
,
args
# make an unbound method
__builtin__
.
__import__
=
types
.
MethodType
(
Y
(),
None
,
(
pseudoclass
,
str
))
import
spam
Python/bltinmodule.c
View file @
48c2ef8a
...
@@ -1245,11 +1245,14 @@ min_max(PyObject *args, PyObject *kwds, int op)
...
@@ -1245,11 +1245,14 @@ min_max(PyObject *args, PyObject *kwds, int op)
"%s() got an unexpected keyword argument"
,
name
);
"%s() got an unexpected keyword argument"
,
name
);
return
NULL
;
return
NULL
;
}
}
Py_INCREF
(
keyfunc
);
}
}
it
=
PyObject_GetIter
(
v
);
it
=
PyObject_GetIter
(
v
);
if
(
it
==
NULL
)
if
(
it
==
NULL
)
{
Py_XDECREF
(
keyfunc
);
return
NULL
;
return
NULL
;
}
maxitem
=
NULL
;
/* the result */
maxitem
=
NULL
;
/* the result */
maxval
=
NULL
;
/* the value associated with the result */
maxval
=
NULL
;
/* the value associated with the result */
...
@@ -1298,6 +1301,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
...
@@ -1298,6 +1301,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
else
else
Py_DECREF
(
maxval
);
Py_DECREF
(
maxval
);
Py_DECREF
(
it
);
Py_DECREF
(
it
);
Py_XDECREF
(
keyfunc
);
return
maxitem
;
return
maxitem
;
Fail_it_item_and_val:
Fail_it_item_and_val:
...
@@ -1308,6 +1312,7 @@ Fail_it:
...
@@ -1308,6 +1312,7 @@ Fail_it:
Py_XDECREF
(
maxval
);
Py_XDECREF
(
maxval
);
Py_XDECREF
(
maxitem
);
Py_XDECREF
(
maxitem
);
Py_DECREF
(
it
);
Py_DECREF
(
it
);
Py_XDECREF
(
keyfunc
);
return
NULL
;
return
NULL
;
}
}
...
...
Python/ceval.c
View file @
48c2ef8a
...
@@ -2066,6 +2066,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
...
@@ -2066,6 +2066,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
"__import__ not found"
);
"__import__ not found"
);
break
;
break
;
}
}
Py_INCREF
(
x
);
v
=
POP
();
v
=
POP
();
u
=
TOP
();
u
=
TOP
();
if
(
PyInt_AsLong
(
u
)
!=
-
1
||
PyErr_Occurred
())
if
(
PyInt_AsLong
(
u
)
!=
-
1
||
PyErr_Occurred
())
...
@@ -2087,11 +2088,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
...
@@ -2087,11 +2088,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
Py_DECREF
(
u
);
Py_DECREF
(
u
);
if
(
w
==
NULL
)
{
if
(
w
==
NULL
)
{
u
=
POP
();
u
=
POP
();
Py_DECREF
(
x
);
x
=
NULL
;
x
=
NULL
;
break
;
break
;
}
}
READ_TIMESTAMP
(
intr0
);
READ_TIMESTAMP
(
intr0
);
x
=
PyEval_CallObject
(
x
,
w
);
v
=
x
;
x
=
PyEval_CallObject
(
v
,
w
);
Py_DECREF
(
v
);
READ_TIMESTAMP
(
intr1
);
READ_TIMESTAMP
(
intr1
);
Py_DECREF
(
w
);
Py_DECREF
(
w
);
SET_TOP
(
x
);
SET_TOP
(
x
);
...
...
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