]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #25961: Disallowed null characters in the type name.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 30 Dec 2015 19:39:21 +0000 (21:39 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 30 Dec 2015 19:39:21 +0000 (21:39 +0200)
Misc/NEWS
Objects/typeobject.c

index 4f3dd8318a6386e3fb730c8ff7b23d2888ce5308..e28bc87fd01966335587c624414d09bdcd60229c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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__,
index a6f3caa4a729f154f755e6712455503296404358..278e485df543e820dea594de190925244bdda81a 100644 (file)
@@ -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;