Skip to content
Draft
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
8 changes: 8 additions & 0 deletions Lib/test/test_ctypes/test_funcptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def c_string(init):
def test_abstract(self):
self.assertRaises(TypeError, _CFuncPtr, 13, "name", 42, "iid")

def test_invalid_argtypes(self):
libc = CDLL(None)

PRINTF_PROTO = CFUNCTYPE(c_int, ctypes.c_char_p)
c_printf = PRINTF_PROTO(("printf", libc), ((1,),))
c_printf.argtypes = (c_char_p, c_int)
with self.assertRaises(TypeError):
c_printf(b"Hello\n")

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix segfaults in _cyptes during _build_callargs.
6 changes: 5 additions & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4374,7 +4374,11 @@ _build_callargs(ctypes_state *st, PyCFuncPtrObject *self, PyObject *argtypes,
callargs = PyTuple_New(len); /* the argument tuple we build */
if (callargs == NULL)
return NULL;

if (!_validate_paramflags(st, Py_TYPE(self), argtypes)) {
PyErr_SetString(PyExc_TypeError,
"the current argument is invalid");
goto error;
}
#ifdef MS_WIN32
/* For a COM method, skip the first arg */
if (self->index) {
Expand Down
Loading