]> granicus.if.org Git - python/commitdiff
#11249: in PyType_FromSpec, copy tp_doc slot since it usually will point to a static...
authorGeorg Brandl <georg@python.org>
Sat, 19 Feb 2011 21:47:02 +0000 (21:47 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 19 Feb 2011 21:47:02 +0000 (21:47 +0000)
Misc/NEWS
Objects/typeobject.c

index 093a126f97a9539ec09ad6b72d2816a3c4b528b6..ff6fd230854394f865132d4fcd56d47ff97df561 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.2?
 Core and Builtins
 -----------------
 
+- Issue #11249: Fix potential crashes when using the limited API.
+
 Library
 -------
 
index e9c7591b818f70797923de2981be8031b41a5fab..b1fe44ebe48ce748fc74d01059df24865a959030 100644 (file)
@@ -2347,6 +2347,17 @@ PyObject* PyType_FromSpec(PyType_Spec *spec)
            goto fail;
        }
        *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc;
+
+        /* need to make a copy of the docstring slot, which usually
+           points to a static string literal */
+        if (slot->slot == Py_tp_doc) {
+            ssize_t len = strlen(slot->pfunc)+1;
+            char *tp_doc = PyObject_MALLOC(len);
+            if (tp_doc == NULL)
+               goto fail;
+            memcpy(tp_doc, slot->pfunc, len);
+            res->ht_type.tp_doc = tp_doc;
+        }
     }
 
     return (PyObject*)res;