[Python-checkins] r59926 - in python/branches/release25-maint: Lib/ctypes Lib/ctypes/test/test_funcptr.py Misc/NEWS Modules/_ctypes Modules/_ctypes/_ctypes.c

thomas.heller python-checkins at python.org
Fri Jan 11 20:48:46 CET 2008


Author: thomas.heller
Date: Fri Jan 11 20:48:46 2008
New Revision: 59926
Modified:
 python/branches/release25-maint/Lib/ctypes/ (props changed)
 python/branches/release25-maint/Lib/ctypes/test/test_funcptr.py
 python/branches/release25-maint/Misc/NEWS
 python/branches/release25-maint/Modules/_ctypes/ (props changed)
 python/branches/release25-maint/Modules/_ctypes/_ctypes.c
Log:
Added NEWS entry, plus:
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.
........
Modified: python/branches/release25-maint/Lib/ctypes/test/test_funcptr.py
==============================================================================
--- python/branches/release25-maint/Lib/ctypes/test/test_funcptr.py	(original)
+++ python/branches/release25-maint/Lib/ctypes/test/test_funcptr.py	Fri Jan 11 20:48:46 2008
@@ -123,5 +123,11 @@
 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()
Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Fri Jan 11 20:48:46 2008
@@ -12,6 +12,8 @@
 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.
Modified: python/branches/release25-maint/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/release25-maint/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/release25-maint/Modules/_ctypes/_ctypes.c	Fri Jan 11 20:48:46 2008
@@ -3305,6 +3305,11 @@
 
 
 	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 */


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /