From: Larry Hastings Date: Wed, 24 Feb 2010 22:49:58 +0000 (+0000) Subject: Issue #5939: Add additional runtime checking to ensure a valid capsule X-Git-Tag: v3.2a1~1632 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1373a0781e28a6aaa595ca3ae145ccd586004ac7;p=thirdparty%2FPython%2Fcpython.git Issue #5939: Add additional runtime checking to ensure a valid capsule in Modules/_ctypes/callproc.c. Reviewed by Benjamin P. My first commit! --- diff --git a/Misc/NEWS b/Misc/NEWS index 8015894e3e51..e384a92873d3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1? Core and Builtins ----------------- +- Issue #5939: Add additional runtime checking to ensure a valid capsule + in Modules/_ctypes/callproc.c. + - Issue #7309: Fix unchecked attribute access when converting UnicodeEncodeError, UnicodeDecodeError, and UnicodeTranslateError to strings. diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index f5eaa0d0babe..2a75fb108485 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -139,8 +139,14 @@ _ctypes_get_errobj(int **pspace) return NULL; } errobj = PyDict_GetItem(dict, error_object_name); - if (errobj) + if (errobj) { + if (!PyCapsule_IsValid(errobj, CTYPES_CAPSULE_NAME_PYMEM)) { + PyErr_SetString(PyExc_RuntimeError, + "ctypes.error_object is an invalid capsule"); + return NULL; + } Py_INCREF(errobj); + } else { void *space = PyMem_Malloc(sizeof(int) * 2); if (space == NULL)