]> granicus.if.org Git - python/commitdiff
Issue #21418: Fix a crash in the builtin function super() when called without
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 12 May 2014 23:32:36 +0000 (01:32 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 12 May 2014 23:32:36 +0000 (01:32 +0200)
argument and without current frame (ex: embedded Python).

Misc/NEWS
Objects/typeobject.c

index cb4fffbe4dbe70427ee9e6ddda2f78e8a97f5a12..0b00ecdbadcc0aa27e1d67f44786effe84599913 100644 (file)
--- 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.
 
index 7f59d5da4050ff3439b3051a39700bfc39733deb..ba106a139a736ba0552bb822cd443bbbfabbe5dc 100644 (file)
@@ -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");