mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Raise an error instead of crashing with a segfault when a NULL
function pointer is called. Will backport to release25-maint.
This commit is contained in:
parent
de68037202
commit
c682614df0
2 changed files with 11 additions and 0 deletions
|
@ -123,5 +123,11 @@ class CFuncPtrTestCase(unittest.TestCase):
|
||||||
self.failUnlessEqual(strtok(None, "\n"), "c")
|
self.failUnlessEqual(strtok(None, "\n"), "c")
|
||||||
self.failUnlessEqual(strtok(None, "\n"), None)
|
self.failUnlessEqual(strtok(None, "\n"), None)
|
||||||
|
|
||||||
|
def test_NULL_funcptr(self):
|
||||||
|
tp = CFUNCTYPE(c_int)
|
||||||
|
func = tp() # NULL function pointer
|
||||||
|
# raise a ValueError when we try to call it
|
||||||
|
self.assertRaises(ValueError, func)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -3312,6 +3312,11 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
|
||||||
|
|
||||||
|
|
||||||
pProc = *(void **)self->b_ptr;
|
pProc = *(void **)self->b_ptr;
|
||||||
|
if (pProc == NULL) {
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"attempt to call NULL function pointer");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#ifdef MS_WIN32
|
#ifdef MS_WIN32
|
||||||
if (self->index) {
|
if (self->index) {
|
||||||
/* It's a COM method */
|
/* It's a COM method */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue