diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-30 21:39:21 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-30 21:39:21 +0200 |
commit | f9347e3b44425c1cb357a0ae76e8756c5894d6c6 (patch) | |
tree | 4ae3c4f442951a722edc30b7da902b556f9d608e | |
parent | ff41d456bcbb3a6122513b4c414bbb32ac0a1223 (diff) | |
download | cpython-git-f9347e3b44425c1cb357a0ae76e8756c5894d6c6.tar.gz |
Issue #25961: Disallowed null characters in the type name.
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Objects/typeobject.c | 15 |
2 files changed, 13 insertions, 4 deletions
@@ -10,6 +10,8 @@ What's New in Python 2.7.12? Core and Builtins ----------------- +- Issue #25961: Disallowed null characters in the type name. + - Issue #22995: Instances of extension types with a state that aren't subclasses of list or dict and haven't implemented any pickle-related methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__, diff --git a/Objects/typeobject.c b/Objects/typeobject.c index a6f3caa4a7..278e485df5 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -244,8 +244,8 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context) } if (strlen(PyString_AS_STRING(value)) != (size_t)PyString_GET_SIZE(value)) { - PyErr_Format(PyExc_ValueError, - "__name__ must not contain null bytes"); + PyErr_SetString(PyExc_ValueError, + "type name must not contain null characters"); return -1; } @@ -2071,8 +2071,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) PyTypeObject *type, *base, *tmptype, *winner; PyHeapTypeObject *et; PyMemberDef *mp; - Py_ssize_t i, nbases, nslots, slotoffset, add_dict, add_weak; - int j, may_add_dict, may_add_weak; + Py_ssize_t i, nbases, nslots, slotoffset; + int j, may_add_dict, may_add_weak, add_dict, add_weak; assert(args != NULL && PyTuple_Check(args)); assert(kwds == NULL || PyDict_Check(kwds)); @@ -2342,6 +2342,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) type->tp_as_mapping = &et->as_mapping; type->tp_as_buffer = &et->as_buffer; 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 */ type->tp_bases = bases; |