]> granicus.if.org Git - python/commitdiff
Added NEWS entry, plus:
authorThomas Heller <theller@ctypes.org>
Fri, 11 Jan 2008 19:48:46 +0000 (19:48 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 11 Jan 2008 19:48:46 +0000 (19:48 +0000)
Merged revisions 59925 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk/Modules/_ctypes

........
  r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fr, 11 Jan 2008) | 5 lines

  Raise an error instead of crashing with a segfault when a NULL
  function pointer is called.

  Will backport to release25-maint.
........

Lib/ctypes/test/test_funcptr.py
Misc/NEWS
Modules/_ctypes/_ctypes.c

index 7ea873f0a4df7dd7d6e77579c9b174b32934cf52..92bf89bb603334d9b25e88238f0ec55d7da969cc 100644 (file)
@@ -123,5 +123,11 @@ class CFuncPtrTestCase(unittest.TestCase):
         self.failUnlessEqual(strtok(None, "\n"), "c")
         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__':
     unittest.main()
index 47b3c5a9a09812270d57b7035a1363814015dc8f..1e742fb374089258578d884e096262e38b1f4351 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.5.2c1?
 Core and builtins
 -----------------
 
+- Prevent a segfault when a ctypes NULL function pointer is called.
+
 - Bug #1517: Possible segfault in lookup().
 
 - Issue #1638: %zd configure test fails on Linux.
index 73b5cbdc2e9e26761e7ed8786f3c260ec7ae411e..47fab8a00a54ac318ba1e6c8ea74541342663327 100644 (file)
@@ -3305,6 +3305,11 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
 
 
        pProc = *(void **)self->b_ptr;
+       if (pProc == NULL) {
+               PyErr_SetString(PyExc_ValueError,
+                               "attempt to call NULL function pointer");
+               return NULL;
+       }
 #ifdef MS_WIN32
        if (self->index) {
                /* It's a COM method */