8000 [3.7] closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930) by miss-islington · Pull Request #8931 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.7] closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (GH-8930) #8931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before d…
…ereferencing it. (GH-8930)

Reported by Svace static analyzer.
(cherry picked from commit 5f79b50)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
  • Loading branch information
Alexey Izbyshev authored and miss-islington committed Aug 25, 2018
commit cb1ee3cf3fce240bb64b48a3c2a09911df573526
13 changes: 9 additions & 4 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2847,15 +2847,22 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
char *res_start = (char*)res;
PyType_Slot *slot;

if (res == NULL)
return NULL;

if (spec->name == NULL) {
PyErr_SetString(PyExc_SystemError,
"Type spec does not define the name field.");
goto fail;
}

/* Set the type name and qualname */
s = strrchr(spec->name, '.');
if (s == NULL)
s = (char*)spec->name;
else
s++;

if (res == NULL)
return NULL;
type = &res->ht_type;
/* The flags must be initialized early, before the GC traverses us */
type->tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;
Expand All @@ -2865,8 +2872,6 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
res->ht_qualname = res->ht_name;
Py_INCREF(res->ht_qualname);
type->tp_name = spec->name;
if (!type->tp_name)
goto fail;

/* Adjust for empty tuple bases */
if (!bases) {
Expand Down
0