[Python-checkins] cpython (2.7): Issue #25961: Disallowed null characters in the type name.

serhiy.storchaka python-checkins at python.org
Wed Dec 30 14:42:15 EST 2015


https://hg.python.org/cpython/rev/29cc6b2f9d28
changeset:   99726:29cc6b2f9d28
branch:      2.7
parent:      99723:32806d3f9bd2
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Dec 30 21:39:21 2015 +0200
summary:
  Issue #25961: Disallowed null characters in the type name.

files:
  Misc/NEWS            |   2 ++
  Objects/typeobject.c |  15 +++++++++++----
  2 files changed, 13 insertions(+), 4 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 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
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -244,8 +244,8 @@
     }
     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 @@
     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->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;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list