Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a crash in `type()` when selecting a metaclass whose `tp_new` slot is `NULL`. Such metaclasses are now rejected with `TypeError` instead of causing a NULL pointer dereference.
7 changes: 7 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5031,6 +5031,13 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type)

if (winner != ctx->metatype) {
if (winner->tp_new != type_new) {
/* Check if tp_new is NULL (cannot instantiate this type) */
if (winner->tp_new == NULL) {
PyErr_Format(PyExc_TypeError,
"cannot create '%.400s' instances",
winner->tp_name);
return -1;
}
/* Pass it to the winner */
*type = winner->tp_new(winner, ctx->args, ctx->kwds);
if (*type == NULL) {
Comment on lines +5034 to 5043
Expand Down
Loading