[Python-checkins] r81324 - python/branches/py3k/Objects/typeobject.c

victor.stinner python-checkins at python.org
Wed May 19 03:42:46 CEST 2010


Author: victor.stinner
Date: Wed May 19 03:42:46 2010
New Revision: 81324

Log:
Issue #6697: Check that _PyUnicode_AsString() result is not NULL in typeobject

Type name and slots are already checked for surrogates somewhere else, but it's
better to ensure that the result is not NULL.


Modified:
   python/branches/py3k/Objects/typeobject.c

Modified: python/branches/py3k/Objects/typeobject.c
==============================================================================
--- python/branches/py3k/Objects/typeobject.c	(original)
+++ python/branches/py3k/Objects/typeobject.c	Wed May 19 03:42:46 2010
@@ -1347,8 +1347,14 @@
     i = 0;
     while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) {
         PyObject *name = class_name(k);
-        off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s",
-                             name ? _PyUnicode_AsString(name) : "?");
+        char *name_str;
+        if (name != NULL) {
+            name_str = _PyUnicode_AsString(name);
+            if (name_str == NULL)
+                name_str = "?"
+        } else
+            name_str = "?"
+        off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", name_str);
         Py_XDECREF(name);
         if (--n && (size_t)(off+1) < sizeof(buf)) {
             buf[off++] = ',';
@@ -2220,6 +2226,10 @@
         for (i = 0; i < nslots; i++, mp++) {
             mp->name = _PyUnicode_AsString(
                 PyTuple_GET_ITEM(slots, i));
+            if (mp->name == NULL) {
+                Py_DECREF(type);
+                return NULL;
+            }
             mp->type = T_OBJECT_EX;
             mp->offset = slotoffset;
 


More information about the Python-checkins mailing list