Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5f99f3

Browse files
author
Victor Stinner
committed
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.
1 parent 8699950 commit e5f99f3

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Objects/typeobject.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,8 +1347,14 @@ consistent method resolution\norder (MRO) for bases");
13471347
i = 0;
13481348
while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) {
13491349
PyObject *name = class_name(k);
1350-
off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s",
1351-
name ? _PyUnicode_AsString(name) : "?");
1350+
char *name_str;
1351+
if (name != NULL) {
1352+
name_str = _PyUnicode_AsString(name);
1353+
if (name_str == NULL)
1354+
name_str = "?"
1355+
} else
1356+
name_str = "?"
1357+
off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", name_str);
13521358
Py_XDECREF(name);
13531359
if (--n && (size_t)(off+1) < sizeof(buf)) {
13541360
buf[off++] = ',';
@@ -2220,6 +2226,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
22202226
for (i = 0; i < nslots; i++, mp++) {
22212227
mp->name = _PyUnicode_AsString(
22222228
PyTuple_GET_ITEM(slots, i));
2229+
if (mp->name == NULL) {
2230+
Py_DECREF(type);
2231+
return NULL;
2232+
}
22232233
mp->type = T_OBJECT_EX;
22242234
mp->offset = slotoffset;
22252235

0 commit comments

Comments
 (0)