Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb1ee3c

Browse files
Alexey Izbyshevmiss-islington
Alexey Izbyshev
authored andcommitted
closes bpo-34501: PyType_FromSpecWithBases: Check spec->name before dereferencing it. (pythonGH-8930)
Reported by Svace static analyzer.(cherry picked from commit5f79b50)Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
1 parent42a1ca6 commitcb1ee3c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎Objects/typeobject.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,15 +2847,22 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
28472847
char*res_start= (char*)res;
28482848
PyType_Slot*slot;
28492849

2850+
if (res==NULL)
2851+
returnNULL;
2852+
2853+
if (spec->name==NULL) {
2854+
PyErr_SetString(PyExc_SystemError,
2855+
"Type spec does not define the name field.");
2856+
gotofail;
2857+
}
2858+
28502859
/* Set the type name and qualname */
28512860
s=strrchr(spec->name,'.');
28522861
if (s==NULL)
28532862
s= (char*)spec->name;
28542863
else
28552864
s++;
28562865

2857-
if (res==NULL)
2858-
returnNULL;
28592866
type=&res->ht_type;
28602867
/* The flags must be initialized early, before the GC traverses us */
28612868
type->tp_flags=spec->flags |Py_TPFLAGS_HEAPTYPE;
@@ -2865,8 +2872,6 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
28652872
res->ht_qualname=res->ht_name;
28662873
Py_INCREF(res->ht_qualname);
28672874
type->tp_name=spec->name;
2868-
if (!type->tp_name)
2869-
gotofail;
28702875

28712876
/* Adjust for empty tuple bases */
28722877
if (!bases) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp