Mercurial > cpython-lru_cache-weakref
diff Objects/typeobject.c @ 43755:704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
with a PyUnicode name.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 02 Nov 2007 23:07:07 +0000 |
| parents | 876b7ef4775d |
| children | 0d462d789b18 |
line wrap: on
line diff
--- a/Objects/typeobject.c Fri Nov 02 16:10:06 2007 +0000 +++ b/Objects/typeobject.c Fri Nov 02 23:07:07 2007 +0000 @@ -45,6 +45,7 @@ { PyHeapTypeObject* et; char *tp_name; + PyObject *tmp; if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { PyErr_Format(PyExc_TypeError, @@ -62,14 +63,22 @@ type->tp_name, Py_Type(value)->tp_name); return -1; } + + /* Check absence of null characters */ + tmp = PyUnicode_FromStringAndSize("\0", 1); + if (tmp == NULL) + return -1; + if (PyUnicode_Contains(value, tmp) != 0) { + Py_DECREF(tmp); + PyErr_Format(PyExc_ValueError, + "__name__ must not contain null bytes"); + return -1; + } + Py_DECREF(tmp); + tp_name = PyUnicode_AsString(value); if (tp_name == NULL) return -1; - if (strlen(tp_name) != (size_t)PyUnicode_GET_SIZE(value)) { - PyErr_Format(PyExc_ValueError, - "__name__ must not contain null bytes"); - return -1; - } et = (PyHeapTypeObject*)type;
