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
5a30620e
Commit
5a30620e
authored
Oct 19, 2018
by
jdemeyer
Committed by
Victor Stinner
Oct 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-25750: Add test on bad descriptor __get__() (GH-9084)
parent
b2e20259
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
Lib/test/test_descr.py
Lib/test/test_descr.py
+21
-0
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+23
-0
No files found.
Lib/test/test_descr.py
View file @
5a30620e
...
...
@@ -13,6 +13,11 @@ import weakref
from
copy
import
deepcopy
from
test
import
support
try
:
import
_testcapi
except
ImportError
:
_testcapi
=
None
class
OperatorsTest
(
unittest
.
TestCase
):
...
...
@@ -4757,6 +4762,22 @@ order (MRO) for bases """
self
.
assertRegex
(
repr
(
method
),
r"<bound method qualname of <object object at .*>>"
)
@
unittest
.
skipIf
(
_testcapi
is
None
,
'need the _testcapi module'
)
def
test_bpo25750
(
self
):
# bpo-25750: calling a descriptor (implemented as built-in
# function with METH_FASTCALL) should not crash CPython if the
# descriptor deletes itself from the class.
class
Descr
:
__get__
=
_testcapi
.
bad_get
class
X
:
descr
=
Descr
()
def
__new__
(
cls
):
cls
.
descr
=
None
# Create this large list to corrupt some unused memory
cls
.
lst
=
[
2
**
i
for
i
in
range
(
10000
)]
X
.
descr
class
DictProxyTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
Modules/_testcapimodule.c
View file @
5a30620e
...
...
@@ -4550,6 +4550,28 @@ new_hamt(PyObject *self, PyObject *args)
}
/* def bad_get(self, obj, cls):
cls()
return repr(self)
*/
static
PyObject
*
bad_get
(
PyObject
*
module
,
PyObject
*
const
*
args
,
Py_ssize_t
nargs
)
{
if
(
nargs
!=
3
)
{
PyErr_SetString
(
PyExc_TypeError
,
"bad_get requires exactly 3 arguments"
);
return
NULL
;
}
PyObject
*
res
=
PyObject_CallObject
(
args
[
2
],
NULL
);
if
(
res
==
NULL
)
{
return
NULL
;
}
Py_DECREF
(
res
);
return
PyObject_Repr
(
args
[
0
]);
}
static
PyObject
*
encode_locale_ex
(
PyObject
*
self
,
PyObject
*
args
)
{
...
...
@@ -5017,6 +5039,7 @@ static PyMethodDef TestMethods[] = {
{
"get_mapping_items"
,
get_mapping_items
,
METH_O
},
{
"test_pythread_tss_key_state"
,
test_pythread_tss_key_state
,
METH_VARARGS
},
{
"hamt"
,
new_hamt
,
METH_NOARGS
},
{
"bad_get"
,
bad_get
,
METH_FASTCALL
},
{
"EncodeLocaleEx"
,
encode_locale_ex
,
METH_VARARGS
},
{
"DecodeLocaleEx"
,
decode_locale_ex
,
METH_VARARGS
},
{
"get_coreconfig"
,
get_coreconfig
,
METH_NOARGS
},
...
...
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