10000 bpo-38748: gh-82929: Add test for stack corruption. by michaelDCurran · Pull Request #26204 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-38748: gh-82929: Add test for stack corruption. #26204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_ctypes/test_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import functools
import unittest
from test import support
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions Modules/_ctypes/_ctypes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
Expand Down
0