mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-138008: Fix segfaults in _ctypes due to invalid argtypes (GH-138285)
Signed-off-by: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com> Signed-off-by: Nguyen Viet Dung <dung@ekluster.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Yongzi Li <204532581+Yzi-Li@users.noreply.github.com>
This commit is contained in:
parent
d54b1091d4
commit
1ce05537a3
3 changed files with 49 additions and 11 deletions
|
|
@ -72,6 +72,32 @@ def test_paramflags(self):
|
|||
self.assertEqual(func(None), None)
|
||||
self.assertEqual(func(input=None), None)
|
||||
|
||||
def test_invalid_paramflags(self):
|
||||
proto = CFUNCTYPE(c_int, c_char_p)
|
||||
with self.assertRaises(ValueError):
|
||||
func = proto(("myprintf", testdll), ((1, "fmt"), (1, "arg1")))
|
||||
|
||||
def test_invalid_setattr_argtypes(self):
|
||||
proto = CFUNCTYPE(c_int, c_char_p)
|
||||
func = proto(("myprintf", testdll), ((1, "fmt"),))
|
||||
|
||||
with self.assertRaisesRegex(TypeError, "_argtypes_ must be a sequence of types"):
|
||||
func.argtypes = 123
|
||||
self.assertEqual(func.argtypes, (c_char_p,))
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "paramflags must have the same length as argtypes"):
|
||||
func.argtypes = (c_char_p, c_int)
|
||||
self.assertEqual(func.argtypes, (c_char_p,))
|
||||
|
||||
def test_paramflags_outarg(self):
|
||||
proto = CFUNCTYPE(c_int, c_char_p, c_int)
|
||||
with self.assertRaisesRegex(TypeError, "must be a pointer type"):
|
||||
func = proto(("myprintf", testdll), ((1, "fmt"), (2, "out")))
|
||||
|
||||
proto = CFUNCTYPE(c_int, c_char_p, c_void_p)
|
||||
func = proto(("myprintf", testdll), ((1, "fmt"), (2, "out")))
|
||||
with self.assertRaisesRegex(TypeError, "must be a pointer type"):
|
||||
func.argtypes = (c_char_p, c_int)
|
||||
|
||||
def test_int_pointer_arg(self):
|
||||
func = testdll._testfunc_p_p
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue