Minimal patch to secure the Python interpreter - Code Review (original) (raw)
OLD
NEW
1 /* Type object implementation */
1 /* Type object implementation */
2
2
3 #include "Python.h"
3 #include "Python.h"
4 #include "structmember.h"
4 #include "structmember.h"
5
5
6 #include <ctype.h>
6 #include <ctype.h>
7
7
8 static PyMemberDef type_members[] = {
8 static PyMemberDef type_members[] = {
9 {"__basicsize__", T_INT, offsetof(PyTypeObject,tp_basicsize),READONLY},
9 {"__basicsize__", T_INT, offsetof(PyTypeObject,tp_basicsize),READONLY},
10 {"__itemsize__", T_INT, offsetof(PyTypeObject, tp_itemsize), READONLY},
10 {"__itemsize__", T_INT, offsetof(PyTypeObject, tp_itemsize), READONLY},
(...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...
2241 */
2241 */
2242 PyObject_Free((char *)type->tp_doc);
2242 PyObject_Free((char *)type->tp_doc);
2243 Py_XDECREF(et->ht_name);
2243 Py_XDECREF(et->ht_name);
2244 Py_XDECREF(et->ht_slots);
2244 Py_XDECREF(et->ht_slots);
2245 type->ob_type->tp_free((PyObject *)type);
2245 type->ob_type->tp_free((PyObject *)type);
2246 }
2246 }
2247
2247
2248 static PyObject *
2248 static PyObject *
2249 type_subclasses(PyTypeObject *type, PyObject *args_ignored)
2249 type_subclasses(PyTypeObject *type, PyObject *args_ignored)
2250 {
2250 {
2251
2252 if (PyEval_GetRestricted()) {
2253 PyErr_SetString(PyExc_RuntimeError,
2254 "__subclasses__ is not accessible in restricted mode.");
2255 return NULL;
2256 }
2257
2251 PyObject *list, *raw, *ref;
2258 PyObject *list, *raw, *ref;
2252 Py_ssize_t i, n;
2259 Py_ssize_t i, n;
2253
2260
2254 list = PyList_New(0);
2261 list = PyList_New(0);
2255 if (list == NULL)
2262 if (list == NULL)
2256 return NULL;
2263 return NULL;
2257 raw = type->tp_subclasses;
2264 raw = type->tp_subclasses;
2258 if (raw == NULL)
2265 if (raw == NULL)
2259 return list;
2266 return list;
2260 assert(PyList_Check(raw));
2267 assert(PyList_Check(raw));
(...skipping 3735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...
5996 0, /* tp_base */
6003 0, /* tp_base */
5997 0, /* tp_dict */
6004 0, /* tp_dict */
5998 super_descr_get, /* tp_descr_get */
6005 super_descr_get, /* tp_descr_get */
5999 0, /* tp_descr_set */
6006 0, /* tp_descr_set */
6000 0, /* tp_dictoffset */
6007 0, /* tp_dictoffset */
6001 super_init, /* tp_init */
6008 super_init, /* tp_init */
6002 PyType_GenericAlloc, /* tp_alloc */
6009 PyType_GenericAlloc, /* tp_alloc */
6003 PyType_GenericNew, /* tp_new */
6010 PyType_GenericNew, /* tp_new */
6004 PyObject_GC_Del, /* tp_free */
6011 PyObject_GC_Del, /* tp_free */
6005 };
6012 };
OLD
NEW