Commit f9347e3b authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #25961: Disallowed null characters in the type name.

parent ff41d456
...@@ -10,6 +10,8 @@ What's New in Python 2.7.12? ...@@ -10,6 +10,8 @@ What's New in Python 2.7.12?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #25961: Disallowed null characters in the type name.
- Issue #22995: Instances of extension types with a state that aren't - Issue #22995: Instances of extension types with a state that aren't
subclasses of list or dict and haven't implemented any pickle-related subclasses of list or dict and haven't implemented any pickle-related
methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__, methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__,
......
...@@ -244,8 +244,8 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context) ...@@ -244,8 +244,8 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
} }
if (strlen(PyString_AS_STRING(value)) if (strlen(PyString_AS_STRING(value))
!= (size_t)PyString_GET_SIZE(value)) { != (size_t)PyString_GET_SIZE(value)) {
PyErr_Format(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"__name__ must not contain null bytes"); "type name must not contain null characters");
return -1; return -1;
} }
...@@ -2071,8 +2071,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) ...@@ -2071,8 +2071,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
PyTypeObject *type, *base, *tmptype, *winner; PyTypeObject *type, *base, *tmptype, *winner;
PyHeapTypeObject *et; PyHeapTypeObject *et;
PyMemberDef *mp; PyMemberDef *mp;
Py_ssize_t i, nbases, nslots, slotoffset, add_dict, add_weak; Py_ssize_t i, nbases, nslots, slotoffset;
int j, may_add_dict, may_add_weak; int j, may_add_dict, may_add_weak, add_dict, add_weak;
assert(args != NULL && PyTuple_Check(args)); assert(args != NULL && PyTuple_Check(args));
assert(kwds == NULL || PyDict_Check(kwds)); assert(kwds == NULL || PyDict_Check(kwds));
...@@ -2342,6 +2342,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) ...@@ -2342,6 +2342,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
type->tp_as_mapping = &et->as_mapping; type->tp_as_mapping = &et->as_mapping;
type->tp_as_buffer = &et->as_buffer; type->tp_as_buffer = &et->as_buffer;
type->tp_name = PyString_AS_STRING(name); type->tp_name = PyString_AS_STRING(name);
if (!type->tp_name)
goto error;
if (strlen(type->tp_name) != (size_t)PyString_GET_SIZE(name)) {
PyErr_SetString(PyExc_ValueError,
"type name must not contain null characters");
goto error;
}
/* Set tp_base and tp_bases */ /* Set tp_base and tp_bases */
type->tp_bases = bases; type->tp_bases = bases;
......
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