Commit 032400b2 authored by Georg Brandl's avatar Georg Brandl

#11249: in PyType_FromSpec, copy tp_doc slot since it usually will point to a...

#11249: in PyType_FromSpec, copy tp_doc slot since it usually will point to a static string literal which should not be deallocated together with the type.
parent e0e824d2
...@@ -10,6 +10,8 @@ What's New in Python 3.2? ...@@ -10,6 +10,8 @@ What's New in Python 3.2?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #11249: Fix potential crashes when using the limited API.
Library Library
------- -------
......
...@@ -2347,6 +2347,17 @@ PyObject* PyType_FromSpec(PyType_Spec *spec) ...@@ -2347,6 +2347,17 @@ PyObject* PyType_FromSpec(PyType_Spec *spec)
goto fail; goto fail;
} }
*(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc; *(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; return (PyObject*)res;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment