From 1c6970fac994be2b1f9e3415e09c07ff01657563 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 13 May 2014 01:32:36 +0200 Subject: Issue #21418: Fix a crash in the builtin function super() when called without argument and without current frame (ex: embedded Python). --- Misc/NEWS | 3 +++ Objects/typeobject.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index cb4fffbe4d..0b00ecdbad 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: TBA Core and Builtins ----------------- +- Issue #21418: Fix a crash in the builtin function super() when called without + argument and without current frame (ex: embedded Python). + - Issue #21425: Fix flushing of standard streams in the interactive interpreter. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 7f59d5da40..ba106a139a 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6919,9 +6919,16 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds) if (type == NULL) { /* Call super(), without args -- fill in from __class__ and first local variable on the stack. */ - PyFrameObject *f = PyThreadState_GET()->frame; - PyCodeObject *co = f->f_code; + PyFrameObject *f; + PyCodeObject *co; Py_ssize_t i, n; + f = PyThreadState_GET()->frame; + if (f == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "super(): no current frame"); + return -1; + } + co = f->f_code; if (co == NULL) { PyErr_SetString(PyExc_RuntimeError, "super(): no code object"); -- cgit v1.2.3