diff Python/ceval.c @ 84529:4f730c045f5f

Issue #18408: Fix call_exc_trace(): if the traceback is NULL, use None when building the tuple (type, value, traceback) passed to the callback. PyTuple_Pack() does crash if an argument is NULL.
author Victor Stinner <vstinner@wyplay.com>
date Wed, 10 Jul 2013 13:57:55 +0200
parents f4311870e329
children d9446c2a2fd4
line wrap: on
line diff
--- a/Python/ceval.c	Tue Jul 09 19:16:32 2013 +0200
+++ b/Python/ceval.c	Wed Jul 10 13:57:55 2013 +0200
@@ -3817,7 +3817,7 @@
 static void
 call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
 {
-    PyObject *type, *value, *traceback, *arg;
+    PyObject *type, *value, *traceback, *orig_traceback, *arg;
     int err;
     PyErr_Fetch(&type, &value, &traceback);
     if (value == NULL) {
@@ -3825,6 +3825,11 @@
         Py_INCREF(value);
     }
     PyErr_NormalizeException(&type, &value, &traceback);
+    orig_traceback = traceback;
+    if (traceback == NULL) {
+        Py_INCREF(Py_None);
+        traceback = Py_None;
+    }
     arg = PyTuple_Pack(3, type, value, traceback);
     if (arg == NULL) {
         PyErr_Restore(type, value, traceback);
@@ -3833,11 +3838,11 @@
     err = call_trace(func, self, f, PyTrace_EXCEPTION, arg);
     Py_DECREF(arg);
     if (err == 0)
-        PyErr_Restore(type, value, traceback);
+        PyErr_Restore(type, value, orig_traceback);
     else {
         Py_XDECREF(type);
         Py_XDECREF(value);
-        Py_XDECREF(traceback);
+        Py_XDECREF(orig_traceback);
     }
 }