diff options
author | Guido van Rossum <guido@python.org> | 2007-11-02 23:07:07 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-11-02 23:07:07 (GMT) |
commit | e845c0f92244ad45a204420e23ebeb53c1a9bd79 (patch) | |
tree | 6e955f6c3bb266d082ab16506b272a91c80b3c01 /Objects | |
parent | 15c974651f7bb8e54a008359cf306a8e8ec13c12 (diff) | |
download | cpython-e845c0f92244ad45a204420e23ebeb53c1a9bd79.zip cpython-e845c0f92244ad45a204420e23ebeb53c1a9bd79.tar.gz cpython-e845c0f92244ad45a204420e23ebeb53c1a9bd79.tar.bz2 |
Fixes for issue 1752184, ensuring type objects are always created
with a PyUnicode name.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index de31ebf..44cf5f1 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -45,6 +45,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context) { PyHeapTypeObject* et; char *tp_name; + PyObject *tmp; if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { PyErr_Format(PyExc_TypeError, @@ -62,14 +63,22 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context) type->tp_name, Py_Type(value)->tp_name); return -1; } - tp_name = PyUnicode_AsString(value); - if (tp_name == NULL) + + /* Check absence of null characters */ + tmp = PyUnicode_FromStringAndSize("\0", 1); + if (tmp == NULL) return -1; - if (strlen(tp_name) != (size_t)PyUnicode_GET_SIZE(value)) { + 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; et = (PyHeapTypeObject*)type; |