Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cpython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sip
Cpython
Commits
d79dd929
Unverified
Commit
d79dd929
authored
Sep 26, 2022
by
Michael Curran
Committed by
GitHub
Sep 26, 2022
Browse files
Options
Downloads
Patches
Plain Diff
bpo-38748: Add ctypes test for stack corruption due to misaligned arguments (GH-26204)
parent
85752dec
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Lib/test/test_ctypes/test_callbacks.py
+13
-0
13 additions, 0 deletions
Lib/test/test_ctypes/test_callbacks.py
Modules/_ctypes/_ctypes_test.c
+13
-0
13 additions, 0 deletions
Modules/_ctypes/_ctypes_test.c
with
26 additions
and
0 deletions
Lib/test/test_ctypes/test_callbacks.py
+
13
−
0
View file @
d79dd929
import
sys
import
functools
import
unittest
from
test
import
support
...
...
@@ -150,6 +151,18 @@ def __del__(self):
gc
.
collect
()
CFUNCTYPE
(
None
)(
lambda
x
=
Nasty
():
None
)
@need_symbol
(
'
WINFUNCTYPE
'
)
def
test_i38748_stackCorruption
(
self
):
callback_funcType
=
WINFUNCTYPE
(
c_long
,
c_long
,
c_longlong
)
@callback_funcType
def
callback
(
a
,
b
):
c
=
a
+
b
print
(
f
"
a=
{
a
}
, b=
{
b
}
, c=
{
c
}
"
)
return
c
dll
=
cdll
[
_ctypes_test
.
__file__
]
# With no fix for i38748, the next line will raise OSError and cause the test to fail.
self
.
assertEqual
(
dll
.
_test_i38748_runCallback
(
callback
,
5
,
10
),
15
)
@need_symbol
(
'
WINFUNCTYPE
'
)
class
StdcallCallbacks
(
Callbacks
):
...
...
This diff is collapsed.
Click to expand it.
Modules/_ctypes/_ctypes_test.c
+
13
−
0
View file @
d79dd929
...
...
@@ -1034,6 +1034,19 @@ EXPORT (HRESULT) KeepObject(IUnknown *punk)
#endif
#ifdef MS_WIN32
// i38748: c stub for testing stack corruption
// When executing a Python callback with a long and a long long
typedef
long
(
__stdcall
*
_test_i38748_funcType
)(
long
,
long
long
);
EXPORT
(
long
)
_test_i38748_runCallback
(
_test_i38748_funcType
callback
,
int
a
,
int
b
)
{
return
callback
(
a
,
b
);
}
#endif
static
struct
PyModuleDef_Slot
_ctypes_test_slots
[]
=
{
{
0
,
NULL
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment