]> granicus.if.org Git - python/commitdiff
Issue #5939: Add additional runtime checking to ensure a valid capsule
authorLarry Hastings <larry@hastings.org>
Wed, 24 Feb 2010 22:49:58 +0000 (22:49 +0000)
committerLarry Hastings <larry@hastings.org>
Wed, 24 Feb 2010 22:49:58 +0000 (22:49 +0000)
in Modules/_ctypes/callproc.c.  Reviewed by Benjamin P.  My first commit!

Misc/NEWS
Modules/_ctypes/callproc.c

index 8015894e3e51abaddb7e75fe31ec98930ac56721..e384a92873d342d7a097cb8d1343a6bfacb7e631 100644 (file)
--- 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.
index f5eaa0d0babec8fe835eb918d8087117815e9fef..2a75fb108485c2278e57459177639842169de513 100644 (file)
@@ -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)