summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2008-05-03 18:24:43 (GMT)
committerAlexandre Vassalotti <alexandre@peadrop.com>2008-05-03 18:24:43 (GMT)
commita85998af7c44c047cb4e35cfa8373330e3f45088 (patch)
tree4f8af4d5cd63bb592f4504b729916a3cf8bb9285 /Objects
parent999679a23ec5731d32dbdbf04b61d4ebb4bcd476 (diff)
downloadcpython-a85998af7c44c047cb4e35cfa8373330e3f45088.zip
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.gz
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.bz2
Issue #1950: Fixed misusage of PyUnicode_AsString().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index e2e365e..2d12a8b 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1255,7 +1255,7 @@ check_duplicates(PyObject *list)
if (PyList_GET_ITEM(list, j) == o) {
o = class_name(o);
PyErr_Format(PyExc_TypeError,
- "duplicate base class %s",
+ "duplicate base class %.400s",
o ? PyUnicode_AsString(o) : "?");
Py_XDECREF(o);
return -1;
@@ -2133,20 +2133,27 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
{
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
if (doc != NULL && PyUnicode_Check(doc)) {
- size_t n;
+ Py_ssize_t len;
+ char *doc_str;
char *tp_doc;
- const char *str = PyUnicode_AsString(doc);
- if (str == NULL) {
+
+ doc_str = PyUnicode_AsStringAndSize(doc, &len);
+ if (doc_str == NULL) {
+ Py_DECREF(type);
+ return NULL;
+ }
+ if ((Py_ssize_t)strlen(doc_str) != len) {
+ PyErr_SetString(PyExc_TypeError,
+ "__doc__ contains null-bytes");
Py_DECREF(type);
return NULL;
}
- n = strlen(str);
- tp_doc = (char *)PyObject_MALLOC(n+1);
+ tp_doc = (char *)PyObject_MALLOC(len + 1);
if (tp_doc == NULL) {
Py_DECREF(type);
return NULL;
}
- memcpy(tp_doc, str, n+1);
+ memcpy(tp_doc, doc_str, len + 1);
type->tp_doc = tp_doc;
}
}